home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2005 August / PCADVD_121.iso / internet / nsb-setup.exe / chrome / browser.jar / content / browser / sitecontrols / sitecontrolsOverlay.js < prev    next >
Encoding:
Text File  |  2005-05-07  |  30.8 KB  |  839 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.  
  442.  
  443.     enableDisableSwitching : function(enable) {
  444.         this.debug('enableDisableSwitching('+enable+')');
  445.         if (enable && !this.switchingEngines) {
  446.             this.mTrustEngine.removeAttribute('disabled');
  447.             this.mTrustGecko.removeAttribute('disabled');
  448.             this.mTrustTrident.removeAttribute('disabled');
  449.             this.mAdvEngine.removeAttribute('disabled');
  450.             this.mAdvGecko.removeAttribute('disabled');
  451.             this.mAdvTrident.removeAttribute('disabled');
  452.         } else {
  453.             this.mTrustEngine.setAttribute('disabled','true');
  454.             this.mTrustGecko.setAttribute('disabled','true');
  455.             this.mTrustTrident.setAttribute('disabled','true');
  456.             this.mAdvEngine.setAttribute('disabled','true');
  457.             this.mAdvGecko.setAttribute('disabled','true');
  458.             this.mAdvTrident.setAttribute('disabled','true');
  459.             setTimeout("scPopup.mTrustEngine.removeAttribute('disabled');", this.engineDisableDelay);
  460.             setTimeout("scPopup.mTrustGecko.removeAttribute('disabled');", this.engineDisableDelay);
  461.             setTimeout("scPopup.mTrustTrident.removeAttribute('disabled');", this.engineDisableDelay);
  462.             setTimeout("scPopup.mAdvEngine.removeAttribute('disabled');", this.engineDisableDelay);
  463.             setTimeout("scPopup.mAdvGecko.removeAttribute('disabled');", this.engineDisableDelay);
  464.             setTimeout("scPopup.mAdvTrident.removeAttribute('disabled');", this.engineDisableDelay);
  465.         }
  466.     },
  467.  
  468.  
  469.     onPopupShown : function(event) {    
  470.         this.debug('onPopupShown()');
  471.         this.init();
  472.         this.mTitleDeck.style.display='-moz-deck';
  473.         this.mTabbox.style.display='-moz-box';
  474.         this.mBtnBar.style.display='-moz-box';
  475.         this.loadCurrentSite();
  476.         this.findSecurityPartners();
  477.         this.dirty = false;
  478.         gBrowser.mCurrentTab.setAttribute("popupvisible", "true");
  479.     },
  480.  
  481.  
  482.     onPopupHidden : function(event) {
  483.         this.mTitleDeck.style.display='none';
  484.         this.mTabbox.style.display='none';
  485.         this.mBtnBar.style.display='none';
  486.         gBrowser.mCurrentTab.setAttribute("popupvisible", "false");
  487.         if (this.dirty)
  488.             BrowserReload();
  489.     },
  490.  
  491.  
  492.     addParent : function(fullURI, event) {
  493.         if (!event.target.id) return;
  494.         
  495.         var tldArray = new Array();
  496.         
  497.         tldArray["AERO"] = "OK";
  498.         tldArray["BIZ"] = "OK";
  499.         tldArray["COM"] = "OK";
  500.         tldArray["COOP"] = "OK";
  501.         tldArray["EDU"] = "OK";
  502.         tldArray["GOV"] = "OK";
  503.         tldArray["INFO"] = "OK";
  504.         tldArray["INT"] = "OK";
  505.         tldArray["MIL"] = "OK";
  506.         tldArray["MUSEUM"] = "OK";
  507.         tldArray["NAME"] = "OK";
  508.         tldArray["NET"] = "OK";
  509.         tldArray["ORG"] = "OK";
  510.         tldArray["PRO"] = "OK";
  511.  
  512.         // Remove any sub domains
  513.         var host = sitecontrols.getStrippedHostFromURL(fullURI);
  514.         if (host && (host != "")) {
  515.             var reg = /.*\.([0-9a-zA-Z\-]+\.[0-9a-zA-Z\-]+)$/;
  516.             if (reg.test(host)) {
  517.                 var ar = reg.exec(host);
  518.                 host = ar[1];
  519.                 
  520.                 var pattern = sitecontrols.SCSVC.getControlledSite(host);
  521.                 if ((pattern != null) || (host && (host != "") && (host != pattern))) {
  522.                     // Just confirm that this is a normal top level domain (ie .com, .org... not .ca, .uk...)
  523.                     reg = /[0-9a-zA-Z\-]+\.([0-9a-zA-Z\-]+)$/;
  524.                     ar = reg.exec(host);
  525.                     var tldPart = ar[1].toUpperCase();
  526.                     if (tldArray[tldPart] == "OK") {
  527.  
  528.                         var sc = sitecontrols.SCSVC;
  529.                         var site = sc.getResourceForURI(host);
  530.                         if (site.Value != sitecontrols.SC_LOCAL)
  531.                         {
  532.                             var pattern = sitecontrols.SCSVC.getControlledSite(host);
  533.                             if ((pattern != null) || (host && (host != "") && (host != pattern))) {
  534.                                 sitecontrols.SCSVC.addControlledSite(host);
  535.                                 site = sitecontrols.SCSVC.getResourceForURI(host);
  536.                             }
  537.                         } else {
  538.                             return;
  539.                         }
  540.  
  541.                         switch (event.target.id) {
  542.                 
  543.                         case 'scp_trust_gecko':
  544.                         case 'scp_trust_trident':
  545.                             sc.updateSiteControlResource(site, 'displayEngine', this.mTrustEngine.value);
  546.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  547.                             break;
  548.                         case 'scp_adv_gecko':
  549.                         case 'scp_adv_trident':
  550.                             sc.updateSiteControlResource(site, 'displayEngine', this.mAdvEngine.value);
  551.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  552.                             break;
  553.                 
  554.                         case 'scp_allowPopups':
  555.                             sc.updateSiteControlResource(site, 'allowPopups',
  556.                                                          (event.target.checked) ? 'true' : 'false');
  557.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  558.                             break;
  559.                 
  560.                         case 'scp_openPopupsInTab':
  561.                             sc.updateSiteControlResource(site, 'requestedPopupsInTab',
  562.                                                          (event.target.checked) ? 'true' : 'false');
  563.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  564.                             break;
  565.                 
  566.                         case 'scp_allowImages':
  567.                             sc.updateSiteControlResource(site, 'allowImages',
  568.                                                          (event.target.checked) ? 'true' : 'false');
  569.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  570.                             break; 
  571.                 
  572.                         case 'scp_imagesFromOrigOnly':
  573.                             sc.updateSiteControlResource(site, 'imagesFromOrigOnly',
  574.                                                          (event.target.checked) ? 'true' : 'false');
  575.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  576.                             break;
  577.                 
  578.                         case 'scp_allowPopupCount':
  579.                             sc.updateSiteControlResource(site, 'showBlockedCount',
  580.                                                          (event.target.checked) ? 'true' : 'false');
  581.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  582.                             break;
  583.                 
  584.                         case 'scp_allowPopupSound':
  585.                             sc.updateSiteControlResource(site, 'playBlockedSound',
  586.                                                          (event.target.checked) ? 'true' : 'false');
  587.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  588.                             break;
  589.                 
  590.                         case 'scp_allowCookies':
  591.                             sc.updateSiteControlResource(site, 'allowCookies',
  592.                                                          (event.target.checked) ? 'true' : 'false');
  593.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  594.                             break;
  595.                 
  596.                         case 'scp_cookiesFromOrigOnly':
  597.                             sc.updateSiteControlResource(site, 'cookiesFromOrigOnly',
  598.                                                          (event.target.checked) ? 'true' : 'false');
  599.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  600.                             break;
  601.                 
  602.                         case 'scp_enableJavaScript':
  603.                             sc.updateSiteControlResource(site, 'enableJavaScript',
  604.                                                          (event.target.checked) ? 'true' : 'false');
  605.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  606.                             break;
  607.                 
  608.                         case 'scp_enableJava':
  609.                             sc.updateSiteControlResource(site, 'enableJava',
  610.                                                          (event.target.checked) ? 'true' : 'false');
  611.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  612.                             break;
  613.                 
  614.                         case 'scp_enableActiveX':
  615.                             sc.updateSiteControlResource(site, 'enableActiveX',
  616.                                                          (event.target.checked) ? 'true' : 'false');
  617.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  618.                             break;
  619.                 
  620.                         case 'scp_radio_trust':
  621.                             sitecontrols.setSecurityLevel(site, 'low');
  622.                             break;
  623.                 
  624.                         case 'scp_radio_standard':
  625.                             sitecontrols.setSecurityLevel(site, 'medium');
  626.                             break;
  627.                 
  628.                         case 'scp_radio_caution':
  629.                             sitecontrols.setSecurityLevel(site, 'high');
  630.                             break;
  631.                 
  632.                         }
  633.                     }
  634.                 }
  635.             }
  636.         }        
  637.     },
  638.  
  639.     onCommand : function(event) {
  640.         this.debug('onCommand()');
  641.         if (!event.target.id) return;
  642.  
  643.         var sc = sitecontrols.SCSVC;
  644.  
  645.         switch (event.target.id) {
  646.  
  647.         case 'scp_trust_gecko':
  648.         case 'scp_trust_trident':
  649.             var site = this.ensureExplicitSiteControl();
  650.             sc.updateSiteControlResource(site, 'displayEngine', this.mTrustEngine.value);
  651.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  652.             this.switchingEngines = true;
  653.             this.enableDisableSwitching(false);
  654.             BrowserReload();
  655.  
  656.             if (event.target.id == 'scp_trust_trident') {
  657.                 this.mAllowCookies.setAttribute('disabled', 'true');
  658.                 this.mCookiesOrig.setAttribute('disabled', 'true');
  659.               sitecontrols.notifyUser('switch_to_ie');
  660.             } else {
  661.                 this.mAllowCookies.removeAttribute('disabled');
  662.                 this.mCookiesOrig.removeAttribute('disabled');
  663.             }
  664.             break;
  665.         case 'scp_adv_gecko':
  666.         case 'scp_adv_trident':
  667.             var site = this.ensureExplicitSiteControl();
  668.             sc.updateSiteControlResource(site, 'displayEngine', this.mAdvEngine.value);
  669.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  670.             this.switchingEngines = true;
  671.             this.enableDisableSwitching(false);
  672.             BrowserReload();
  673.  
  674.  
  675.             if (event.target.id == 'scp_adv_trident') {
  676.               sitecontrols.notifyUser('switch_to_ie');
  677.             }
  678.                 
  679.             break;
  680.  
  681.         case 'scp_allowPopups':
  682.             var site = this.ensureExplicitSiteControl();
  683.             sc.updateSiteControlResource(site, 'allowPopups',
  684.                                          (event.target.checked) ? 'true' : 'false');
  685.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  686.             //this.dirty = true;
  687.             BrowserReload();
  688.             break;
  689.  
  690.         case 'scp_openPopupsInTab':
  691.             var site = this.ensureExplicitSiteControl();
  692.             sc.updateSiteControlResource(site, 'requestedPopupsInTab',
  693.                                          (event.target.checked) ? 'true' : 'false');
  694.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  695.             BrowserReload();
  696.             break;
  697.  
  698.         case 'scp_allowImages':
  699.             var site = this.ensureExplicitSiteControl();
  700.             sc.updateSiteControlResource(site, 'allowImages',
  701.                                          (event.target.checked) ? 'true' : 'false');
  702.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  703.             BrowserReload();
  704.             break; 
  705.  
  706.         case 'scp_imagesFromOrigOnly':
  707.             var site = this.ensureExplicitSiteControl();
  708.             sc.updateSiteControlResource(site, 'imagesFromOrigOnly',
  709.                                          (event.target.checked) ? 'true' : 'false');
  710.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  711.             BrowserReload();
  712.             break;
  713.  
  714.         case 'scp_allowPopupCount':
  715.             var site = this.ensureExplicitSiteControl();
  716.             sc.updateSiteControlResource(site, 'showBlockedCount',
  717.                                          (event.target.checked) ? 'true' : 'false');
  718.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  719.             BrowserReload();
  720.             break;
  721.  
  722.         case 'scp_allowPopupSound':
  723.             var site = this.ensureExplicitSiteControl();
  724.             sc.updateSiteControlResource(site, 'playBlockedSound',
  725.                                          (event.target.checked) ? 'true' : 'false');
  726.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  727.             BrowserReload();
  728.             break;
  729.  
  730.         case 'scp_allowCookies':
  731.             var site = this.ensureExplicitSiteControl();
  732.             sc.updateSiteControlResource(site, 'allowCookies',
  733.                                          (event.target.checked) ? 'true' : 'false');
  734.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  735.             BrowserReload();
  736.             if (!event.target.checked) sitecontrols.notifyUser('disable_cookies');
  737.             break;
  738.  
  739.         case 'scp_cookiesFromOrigOnly':
  740.             var site = this.ensureExplicitSiteControl();
  741.             sc.updateSiteControlResource(site, 'cookiesFromOrigOnly',
  742.                                          (event.target.checked) ? 'true' : 'false');
  743.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  744.             BrowserReload();
  745.             break;
  746.  
  747.         case 'scp_enableJavaScript':
  748.             var site = this.ensureExplicitSiteControl();
  749.             sc.updateSiteControlResource(site, 'enableJavaScript',
  750.                                          (event.target.checked) ? 'true' : 'false');
  751.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  752.             BrowserReload();
  753.             if (!event.target.checked) sitecontrols.notifyUser('disable_javascript');
  754.             break;
  755.  
  756.         case 'scp_enableJava':
  757.             var site = this.ensureExplicitSiteControl();
  758.             sc.updateSiteControlResource(site, 'enableJava',
  759.                                          (event.target.checked) ? 'true' : 'false');
  760.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  761.             BrowserReload();
  762.             break;
  763.  
  764.         case 'scp_enableActiveX':
  765.             var site = this.ensureExplicitSiteControl();
  766.             sc.updateSiteControlResource(site, 'enableActiveX',
  767.                                          (event.target.checked) ? 'true' : 'false');
  768.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  769.             BrowserReload();
  770.             if (event.target.checked) sitecontrols.notifyUser('enable_activex');
  771.             break;
  772.  
  773.         case 'scp_radio_trust':
  774.             var site = this.ensureExplicitSiteControl();
  775.             sitecontrols.setSecurityLevel(site, 'low');
  776.             BrowserReload();
  777.             break;
  778.  
  779.         case 'scp_radio_standard':
  780.             var site = this.ensureExplicitSiteControl();
  781.             sitecontrols.setSecurityLevel(site, 'medium');
  782.             BrowserReload();
  783.             break;
  784.  
  785.         case 'scp_radio_caution':
  786.             var site = this.ensureExplicitSiteControl();
  787.             sitecontrols.setSecurityLevel(site, 'high');
  788.             BrowserReload();
  789.             break;
  790.  
  791.         default:
  792.             return;
  793.         }
  794.         
  795.         this.addParent(this.currentURI.spec, event);        
  796.         this.loadCurrentSite();
  797.     },
  798.  
  799.  
  800.     ensureExplicitSiteControl : function() {
  801.         var sc = sitecontrols.SCSVC;
  802.         var site = sc.getResourceForURI(this.currentURI.spec);
  803.         if (site.Value != sitecontrols.SC_LOCAL)
  804.         {
  805.             var host = sitecontrols.getStrippedHostFromURL(this.currentURI.spec);
  806.             var pattern = sitecontrols.SCSVC.getControlledSite(host);
  807.             if ((pattern != null) || (host && (host != "") && (host != pattern))) {
  808.                 sitecontrols.SCSVC.addControlledSite(host);
  809.                 site = sitecontrols.SCSVC.getResourceForURI(host);
  810.             }
  811.         }
  812.         return site;
  813.     },
  814.  
  815.     manageSiteList : function() {
  816.         this.close(document.getElementById('SiteControlsPopup'));
  817.         openSiteControlPrefs();
  818.     },
  819.  
  820.  
  821.     close : function(elm) {
  822.         while (elm.localName != 'popup')
  823.             elm = elm.parentNode;
  824.         elm.hidePopup();
  825.     },
  826.  
  827.     debug : function(msg) {
  828.         if (this.DEBUG)
  829.             dump('sitecontrolsOverlay.js: '+msg+'\n');
  830.     }
  831. };
  832.  
  833.  
  834. function showSiteControlsPopup(x, y) {
  835.     var myTab = gBrowser.selectedTab;
  836.     var siteControlPopup = document.getElementById('SiteControlsPopup');
  837.     document.getElementById('SiteControlsPopup')
  838.             .showPopup(myTab, -1, -1, "popup", "bottomleft", "topleft");
  839. }