home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / browser.jar / content / browser / pref / pref-advanced.xul < prev    next >
Extensible Markup Language  |  2002-11-01  |  12KB  |  340 lines

  1. <?xml version="1.0"?> 
  2.  
  3. <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
  4.  
  5. <!DOCTYPE page [
  6. <!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd">
  7. %brandDTD;
  8. <!ENTITY % prefAdvancedDTD SYSTEM "chrome://browser/locale/pref/pref-advanced.dtd"> %prefAdvancedDTD;
  9. ]>
  10.  
  11. <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  12.       onload="parent.initPanel('chrome://browser/content/pref/pref-advanced.xul');"
  13.       headertitle="&lHeader;">
  14.  
  15.   <stringbundle id="stringBundle" src="chrome://browser/locale/pref/addPopup.properties"/>
  16.  
  17.   <script type="application/x-javascript">
  18.   <![CDATA[
  19.     var _elementIDs = ["advancedJavaAllow", "advancedMailFTP", "advancedMailFTPAddress",
  20.                        "popupPolicy"];   
  21.     
  22.     var policyButton;
  23.     var manageTree;
  24.     function Startup() {
  25.       ftpCheck();
  26.       policyButton = document.getElementById("popupPolicy");
  27.       manageTree = document.getElementById("permissionsTree");
  28.       toggleEnabling();
  29.       loadPermissions();
  30.     }
  31.     function ftpCheck() {
  32.       var checked = document.getElementById("advancedMailFTP").checked;
  33.       var field = document.getElementById("advancedMailFTPAddress");
  34.       field.disabled = !checked;
  35.       if (checked)
  36.         field.focus();
  37.     }
  38.  
  39.     function toggleEnabling() {
  40.       var enabled = policyButton.checked;
  41.       var add = document.getElementById("addPermission");
  42.       var remove1 = document.getElementById("removePermission");
  43.       var remove2 = document.getElementById("removeAllPermissions");
  44.       var description = document.getElementById("popupDescription");
  45.       add.disabled = !enabled;
  46.       remove1.disabled = !enabled;
  47.       remove2.disabled = !enabled;
  48.       description.disabled = !enabled;
  49.       manageTree.disabled = !enabled;
  50.     }
  51.  
  52.   
  53.   /*** =================== PERMISSIONS CODE =================== ***/
  54.   
  55.   var permissionsTreeView = {
  56.     rowCount : 0,
  57.     setTree : function(tree){},
  58.     getImageSrc : function(row,column) {},
  59.     getProgressMode : function(row,column) {},
  60.     getCellValue : function(row,column) {},
  61.     getCellText : function(row,column){
  62.       var rv="";
  63.       if (column=="siteCol") {
  64.         rv = permissions[row].rawHost;
  65.       } else if (column=="statusCol") {
  66.         rv = permissions[row].capability;
  67.       }
  68.       return rv;
  69.     },
  70.     isSeparator : function(index) {return false;},
  71.     isSorted: function() { return false; },
  72.     isContainer : function(index) {return false;},
  73.     cycleHeader : function(aColId, aElt) {},
  74.     getRowProperties : function(row,column,prop){},
  75.     getColumnProperties : function(column,columnElement,prop){},
  76.     getCellProperties : function(row,prop){}
  77.    };
  78.   var permissionsTree;
  79.   
  80.   var permissions           = [];
  81.   var deletedPermissions   = [];
  82.   
  83.   function Permission(number, host, rawHost, type, capability) {
  84.     this.number = number;
  85.     this.host = host;
  86.     this.rawHost = rawHost;
  87.     this.type = type;
  88.     this.capability = capability;
  89.   }
  90.   
  91.   var permissionmanager = Components.classes["@mozilla.org/permissionmanager;1"].getService();
  92.   permissionmanager = permissionmanager.QueryInterface(Components.interfaces.nsIPermissionManager);
  93.   var popupmanager = Components.classes["@mozilla.org/PopupWindowManager;1"].getService();
  94.   popupmanager = popupmanager.QueryInterface(Components.interfaces.nsIPopupWindowManager);
  95.   
  96.   function DeleteAllFromTree
  97.       (tree, view, table, deletedTable, removeButton, removeAllButton) {
  98.   
  99.     // remove all items from table and place in deleted table
  100.     for (var i=0; i<table.length; i++) {
  101.       deletedTable[deletedTable.length] = table[i];
  102.     }
  103.     table.length = 0;
  104.   
  105.     // clear out selections
  106.     tree.treeBoxObject.view.selection.select(-1); 
  107.   
  108.     // redisplay
  109.     view.rowCount = 0;
  110.     tree.treeBoxObject.invalidate();
  111.   
  112.   
  113.     // disable buttons
  114.     document.getElementById(removeButton).setAttribute("disabled", "true")
  115.     document.getElementById(removeAllButton).setAttribute("disabled","true");
  116.   }
  117.   
  118.   function DeleteSelectedItemFromTree
  119.       (tree, view, table, deletedTable, removeButton, removeAllButton) {
  120.   
  121.     // remove selected items from list (by setting them to null) and place in deleted list
  122.     var selections = GetTreeSelections(tree);
  123.     for (var s=selections.length-1; s>= 0; s--) {
  124.       var i = selections[s];
  125.       deletedTable[deletedTable.length] = table[i];
  126.       table[i] = null;
  127.     }
  128.   
  129.     // collapse list by removing all the null entries
  130.     for (var j=0; j<table.length; j++) {
  131.       if (table[j] == null) {
  132.         var k = j;
  133.         while ((k < table.length) && (table[k] == null)) {
  134.           k++;
  135.         }
  136.         table.splice(j, k-j);
  137.       }
  138.     }
  139.   
  140.     // redisplay
  141.     var box = tree.treeBoxObject;
  142.     var firstRow = box.getFirstVisibleRow();
  143.     if (firstRow > (table.length-1) ) {
  144.       firstRow = table.length-1;
  145.     }
  146.     view.rowCount = table.length;
  147.     box.rowCountChanged(0, table.length);
  148.     box.scrollToRow(firstRow)
  149.   
  150.     // update selection and/or buttons
  151.     if (table.length) {
  152.   
  153.       // update selection
  154.       // note: we need to deselect before reselecting in order to trigger ...Selected method
  155.       var nextSelection = (selections[0] < table.length) ? selections[0] : table.length-1;
  156.       tree.treeBoxObject.view.selection.select(-1); 
  157.       tree.treeBoxObject.view.selection.select(nextSelection);
  158.   
  159.     } else {
  160.   
  161.       // disable buttons
  162.       document.getElementById(removeButton).setAttribute("disabled", "true")
  163.       document.getElementById(removeAllButton).setAttribute("disabled","true");
  164.   
  165.       // clear out selections
  166.       tree.treeBoxObject.view.selection.select(-1); 
  167.     }
  168.   }
  169.   
  170.   function GetTreeSelections(tree) {
  171.     var selections = [];
  172.     var select = tree.treeBoxObject.selection;
  173.     if (select) {
  174.       var count = select.getRangeCount();
  175.       var min = new Object();
  176.       var max = new Object();
  177.       for (var i=0; i<count; i++) {
  178.         select.getRangeAt(i, min, max);
  179.         for (var k=min.value; k<=max.value; k++) {
  180.           if (k != -1) {
  181.             selections[selections.length] = k;
  182.           }
  183.         }
  184.       }
  185.     }
  186.     return selections;
  187.   }
  188.   
  189.   function loadPermissions() {
  190.     // load permissions into a table
  191.     if (!permissionsTree)
  192.       permissionsTree = document.getElementById("permissionsTree");
  193.   
  194.     var enumerator = permissionmanager.enumerator;
  195.     var count = 0;
  196.     var contentStr;
  197.     var dialogType = 2; // Popups
  198.    
  199.     while (enumerator.hasMoreElements()) {
  200.       var nextPermission = enumerator.getNext();
  201.       nextPermission = nextPermission.QueryInterface(Components.interfaces.nsIPermission);
  202.       if (nextPermission.type == dialogType) {
  203.         var host = nextPermission.host;
  204.         permissions[count] = 
  205.           new Permission(count++, host,
  206.                          (host.charAt(0)==".") ? host.substring(1,host.length) : host,
  207.                          nextPermission.type,
  208.                          "");
  209.       }
  210.     }
  211.     permissionsTreeView.rowCount = permissions.length;
  212.   
  213.     // sort and display the table
  214.     permissionsTree.treeBoxObject.view = permissionsTreeView;
  215.     
  216.     // disable "remove all" button if there are no popups
  217.     if (permissions.length == 0) {
  218.       document.getElementById("removeAllPermissions").setAttribute("disabled","true");
  219.     } else {
  220.       document.getElementById("removeAllPermissions").removeAttribute("disabled");
  221.     }
  222.   }
  223.   
  224.   function PermissionSelected() {
  225.     var selections = GetTreeSelections(permissionsTree);
  226.     if (selections.length) {
  227.       document.getElementById("removePermission").removeAttribute("disabled");
  228.     }
  229.   }
  230.   
  231.   function AddPermission() {
  232.     var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  233.                                 .getService(Components.interfaces.nsIPromptService);
  234.  
  235.     var stringBundle = document.getElementById("stringBundle");
  236.     var message = stringBundle.getString("enterSiteName");
  237.     var title = stringBundle.getString("enterSiteTitle");
  238.   
  239.     var name = {};
  240.     if (!promptService.prompt(window, title, message, name, null, {}))
  241.         return;
  242.       
  243.     var nameToURI = name.value.replace(" ", "");    
  244.     var uri = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI);
  245.     uri.spec = nameToURI;
  246.     popupmanager.add(uri, true);
  247.     loadPermissions();
  248.   }
  249.  
  250.   function DeletePermission() {
  251.     DeleteSelectedItemFromTree(permissionsTree, permissionsTreeView,
  252.                                    permissions, deletedPermissions,
  253.                                    "removePermission", "removeAllPermissions");
  254.     FinalizePermissionDeletions();
  255.   }
  256.   
  257.   function DeleteAllPermissions() {
  258.     DeleteAllFromTree(permissionsTree, permissionsTreeView,
  259.                           permissions, deletedPermissions,
  260.                           "removePermission", "removeAllPermissions");
  261.     FinalizePermissionDeletions();
  262.   }
  263.   
  264.   function FinalizePermissionDeletions() {
  265.     var ioService = Components.classes["@mozilla.org/network/io-service;1"]
  266.                       .getService(Components.interfaces.nsIIOService);
  267.   
  268.     for (var p=0; p<deletedPermissions.length; p++) {
  269.       if (deletedPermissions[p].type == 2) {
  270.         // we lost the URI's original scheme, but this will do because the scheme
  271.         // is stripped later anyway.
  272.         var uri = ioService.newURI("http://"+deletedPermissions[p].host, null, null);
  273.         popupmanager.remove(uri);
  274.       } else
  275.         permissionmanager.remove(deletedPermissions[p].host, deletedPermissions[p].type);
  276.     }
  277.     deletedPermissions.length = 0;
  278.   }
  279.   
  280.   function HandlePermissionKeyPress(e) {
  281.     if (e.keyCode == 46) {
  282.       DeletePermission();
  283.     }
  284.   }
  285.  
  286.   ]]>
  287.   </script>
  288.  
  289.   <groupbox>
  290.     <caption label="&general.label;"/>
  291.     <checkbox id="advancedJavaAllow" label="&enbJavaCheck.label;" accesskey="&enbJavaCheck.accesskey;"
  292.               prefstring="security.enable_java"/>
  293.     <checkbox id="advancedMailFTP" label="&sendAddFtpCheck.label;" accesskey="&sendAddFtpCheck.accesskey;"
  294.               prefstring="advanced.mailftp"
  295.               oncommand="ftpCheck();"/>
  296.     <hbox class="indent" flex="1">
  297.       <textbox id="advancedMailFTPAddress"
  298.                preftype="string" prefstring="network.ftp.anonymous_password"
  299.                flex="2"/>
  300.     </hbox>
  301.   </groupbox>
  302.  
  303.   <groupbox id="popupsArea" flex="1">
  304.     <caption>
  305.       <checkbox label="&popupReject.label;"
  306.                 prefstring="dom.disable_open_during_load"
  307.                 accesskey="&popupReject.accesskey;"
  308.                 oncommand="toggleEnabling()" id="popupPolicy"/>
  309.    </caption>
  310.   
  311.     <vbox id="servers" flex="1">
  312.         <label id="popupDescription" value="&div.blessedservers.label;"/>
  313.         <separator class="thin"/>
  314.         <tree id="permissionsTree" flex="1"
  315.               seltype="multiple" hidecolumnpicker="true"
  316.               onkeypress="HandlePermissionKeyPress(event)"
  317.               onselect="PermissionSelected();">
  318.           <treecols>
  319.             <treecol id="siteCol" hideheader="true" flex="1"/>
  320.           </treecols>
  321.           <treechildren/>
  322.         </tree>
  323.         <hbox>
  324.           <button id="addPermission" disabled="true"
  325.                         label="&addpermission.label;"
  326.                         oncommand="AddPermission();"/>
  327.           <button id="removePermission" disabled="true" 
  328.                         label="&removepermission.label;" 
  329.                         oncommand="DeletePermission();"/>
  330.           <button id="removeAllPermissions"
  331.                         label="&removeallpermissions.label;" 
  332.                         oncommand="DeleteAllPermissions();"/>
  333.         </hbox>
  334.     </vbox>
  335.   
  336.   </groupbox>
  337. </page>
  338.  
  339.  
  340.