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 / pref / plugins.js < prev    next >
Encoding:
Text File  |  2005-07-29  |  8.9 KB  |  263 lines

  1.  
  2. var gPluginTypes = null;
  3. var gPluginTypesList = null;
  4.  
  5. var gPrefs = null;
  6.  
  7. const kDisabledPluginTypesPref = "browser.download.pluginOverrideTypes";
  8. const kPluginHandlerContractID = "@mozilla.org/content/plugin/document-loader-factory;1";
  9. const kPluginOverrideTypesNotHandled = "browser.download.pluginOverrideTypesNotHandled";
  10.  
  11. function init()
  12. {
  13.   gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  14.   
  15.   gPluginTypes = new PluginTypes();
  16.  
  17.   // Initialize the File Type list
  18.   gPluginTypesList = document.getElementById("pluginTypesList");
  19.   gPluginTypesList.treeBoxObject.view = gPluginTypes;
  20.   
  21.   var x = document.documentElement.getAttribute("screenX");
  22.   if (x == "")
  23.     setTimeout(centerOverParent, 0);  
  24. }
  25.  
  26. // This should actually go into some sort of pref fe utilities file. 
  27. function centerOverParent()
  28. {
  29.   var parent = window.opener;
  30.   
  31.   x = parent.screenX + (parent.outerWidth / 2) - (window.outerWidth / 2);
  32.   y = parent.screenY + (parent.outerHeight / 2) - (window.outerHeight / 2);
  33.   window.moveTo(x, y);
  34. }
  35.  
  36. function onAccept()
  37. {
  38.   var catman = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
  39.  
  40.   // Update the disabled plugin types pref and the category manager.
  41.   var disabled = "";
  42.   for (var i = 0; i < gPluginTypes._pluginTypes.length; ++i) {
  43.     var currType = gPluginTypes._pluginTypes[i];
  44.  
  45.     if (!currType.pluginEnabled) {
  46.       for (var j = 0; j < currType.MIMETypes.length; ++j) {
  47.         disabled += currType.MIMETypes[j] + ",";
  48.         catman.deleteCategoryEntry("Gecko-Content-Viewers", currType.MIMETypes[j], false);
  49.       }
  50.     }
  51.     else {
  52.       // We could have re-activated a deactivated Plugin handler, add all the handlers back again, 
  53.       // replacing the existing ones. 
  54.       for (j = 0; j < currType.MIMETypes.length; ++j)
  55.         catman.addCategoryEntry("Gecko-Content-Viewers", currType.MIMETypes[j], 
  56.                                 kPluginHandlerContractID, false, true);
  57.     }
  58.   }
  59.   
  60.   if (disabled != "") {  
  61.     disabled = disabled.substr(0, disabled.length - 1);
  62.     
  63.     gPrefs.setCharPref(kDisabledPluginTypesPref, disabled);
  64.   }
  65.   else if (gPrefs.prefHasUserValue(kDisabledPluginTypesPref)) {
  66.     // Clear the pref if we've restored plugin functionality to all
  67.     // listed types. 
  68.     gPrefs.clearUserPref(kDisabledPluginTypesPref); 
  69.   }
  70. }
  71.  
  72. function PluginType (aPluginEnabled, aMIMEInfo) 
  73. {
  74.   this.pluginEnabled = aPluginEnabled;
  75.   this.MIMEInfo = aMIMEInfo;
  76.   this.MIMETypes = [this.MIMEInfo.MIMEType];
  77. }
  78.  
  79. function PluginTypes()
  80. {
  81.   var atomSvc = Components.classes["@mozilla.org/atom-service;1"].getService(Components.interfaces.nsIAtomService);
  82.   this._enabledAtom = atomSvc.getAtom("enabled");
  83.  
  84.   this._pluginTypes = [];
  85.   this._pluginTypeHash = { };
  86.  
  87.   // Read enabled plugin type information from the category manager
  88.   var catman = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
  89.   var types = catman.enumerateCategory("Gecko-Content-Viewers");
  90.   while (types.hasMoreElements()) {
  91.     var currType = types.getNext().QueryInterface(Components.interfaces.nsISupportsCString).data;
  92.     var contractid = catman.getCategoryEntry("Gecko-Content-Viewers", currType);
  93.     if (contractid == kPluginHandlerContractID)
  94.       this.addType(currType, true);
  95.   }
  96.   
  97.   // Read disabled plugin type information from preferences
  98.   try {
  99.     var types = gPrefs.getCharPref(kDisabledPluginTypesPref);
  100.     var disabledTypes = types.split(",");
  101.     
  102.     // Don't show types for which there is no plugin configured, even if that type
  103.     // is listed in the override list. This may be because the user is running a different
  104.     // build with a profile that was used in another build that had other plugins installed.
  105.     // We don't want to clobber the override list and we also don't want to display the
  106.     // entries for the plugins that aren't configured. 
  107.     var validOverrides = { };
  108.     if (gPrefs.prefHasUserValue(kPluginOverrideTypesNotHandled)) {
  109.       var notHandledTypes = gPrefs.getCharPref(kPluginOverrideTypesNotHandled);
  110.       notHandledTypes = notHandledTypes.split(",");
  111.       
  112.       for (var i = 0; i < notHandledTypes.length; ++i)
  113.         validOverrides[notHandledTypes[i]] = notHandledTypes[i];
  114.     }
  115.     
  116.     for (i = 0; i < disabledTypes.length; ++i) {
  117.       if (!(disabledTypes[i] in validOverrides)) 
  118.         this.addType(disabledTypes[i], false);
  119.     }
  120.   }
  121.   catch (e) { }
  122.   
  123.   this._pluginTypes.sort(this.sortCallback);
  124. }
  125.  
  126. PluginTypes.prototype = {
  127.   addType: function (aMIMEType, aPluginEnabled)
  128.   {
  129.     var mimeInfo = this.getMIMEInfoForType(aMIMEType);
  130.     if (mimeInfo) {
  131.       // We only want to show one entry per extension, even if several MIME
  132.       // types map to that extension, e.g. audio/wav, audio/x-wav. Hash the
  133.       // primary extension for the type to prevent duplicates. If we encounter
  134.       // a duplicate, record the additional MIME type so we know to deactivate
  135.       // support for it too if the user deactivates support for the extension.
  136.       try {
  137.         var primExt = mimeInfo.primaryExtension;
  138.       } catch (e) { }
  139.  
  140.       if (primExt) {
  141.         // If there's no extension, there's nothing to do here.
  142.         if (!(primExt in this._pluginTypeHash)) {
  143.           var pluginType = new PluginType(aPluginEnabled, mimeInfo);
  144.           this._pluginTypeHash[primExt] = pluginType;
  145.           this._pluginTypes.push(pluginType);
  146.         }
  147.         // We check that the primary extension has already been hashed
  148.         // by a plugin that is installed in this build before adding a disable
  149.         // override to the list. Otherwise we might end up showing disabled
  150.         // plugin entries for plugins that actually aren't installed and configured
  151.         // in this build, but were for another build that was using this profile.
  152.         else {
  153.           // Append this MIME type to the list of MIME types for the extension.
  154.           var pluginType = this._pluginTypeHash[primExt];
  155.           pluginType.MIMETypes.push(mimeInfo.MIMEType);
  156.         }
  157.       }
  158.     }
  159.   },
  160.  
  161.   sortCallback: function (a, b)
  162.   {
  163.     try {
  164.       var ac = a.MIMEInfo.primaryExtension.toLowerCase();
  165.       var bc = b.MIMEInfo.primaryExtension.toLowerCase();
  166.     } catch (e) { }
  167.     
  168.     if (ac < bc) 
  169.       return -1;
  170.     else if (ac > bc) 
  171.       return 1;
  172.     return 0;
  173.   },
  174.  
  175.   getMIMEInfoForType: function (aType)
  176.   {
  177.     try {
  178.       var mimeSvc = Components.classes["@mozilla.org/mime;1"].getService(Components.interfaces.nsIMIMEService);
  179.       return mimeSvc.getFromTypeAndExtension(aType, "");
  180.     }
  181.     catch (e) {
  182.       dump("getMIMEInfoForType: Exception! "+e);
  183.     }
  184.     
  185.     return null;
  186.   },
  187.  
  188.   // nsITreeView
  189.   get rowCount() 
  190.   { 
  191.     return this._pluginTypes.length; 
  192.   },
  193.  
  194.   getCellProperties: function (aRow, aCol, aProperties) 
  195.   { 
  196.     if (aCol == "pluginEnabled") {
  197.       if (this._pluginTypes[aRow].pluginEnabled) 
  198.         aProperties.AppendElement(this._enabledAtom);
  199.     }
  200.   },
  201.   
  202.   getImageSrc: function (aRow, aCol) 
  203.   { 
  204.     if (aCol == "fileExtension") 
  205.       return "moz-icon://goat." + this._pluginTypes[aRow].MIMEInfo.primaryExtension + "?size=16";
  206.     
  207.     return null;
  208.   },
  209.   
  210.   getCellText: function (aRow, aCol) 
  211.   { 
  212.     var mimeInfo = this._pluginTypes[aRow].MIMEInfo;
  213.     
  214.     if (aCol == "fileType") {
  215.       var desc = mimeInfo.Description;
  216.       // XXXben localize
  217.       return desc || mimeInfo.primaryExtension.toUpperCase() + " file";
  218.     }
  219.     else if (aCol == "fileExtension")
  220.       return mimeInfo.primaryExtension.toUpperCase();
  221.  
  222.     return "";    
  223.   },
  224.   
  225.   cycleCell: function (aRow, aCol) 
  226.   { 
  227.     if (aCol == "pluginEnabled") {
  228.       this._pluginTypes[aRow].pluginEnabled = !this._pluginTypes[aRow].pluginEnabled;
  229.       gPluginTypesList.treeBoxObject.invalidateCell(aRow, aCol);
  230.     }
  231.   },
  232.  
  233.   selection: null,
  234.   
  235.   // Stuff we don't need...
  236.   isContainer: function (aRow) { return false; },
  237.   isContainerOpen: function (aRow) { return false; },
  238.   isContainerEmpty: function (aRow) { return true; },
  239.   isSeparator: function (aRow) { return false; },
  240.   isSorted: function () { return false; },
  241.   canDropOn: function (aRow) { return false; },
  242.   canDropBeforeAfter: function (aRow, aBefore) { return false; },
  243.   drop: function (aRow, aOrientation) { },
  244.   getParentIndex: function (aRow) { },
  245.   hasNextSibling: function (aRow, aNextIndex) { },
  246.   getLevel: function (aRow) { },
  247.   getProgressMode: function (aRow, aCol) { },
  248.   getCellValue: function (aRow, aCol) { },
  249.   setTree: function (aTree) { },
  250.   toggleOpenState: function (aRow) { },
  251.   cycleHeader: function (aCol, aColElt) { },
  252.   selectionChanged: function () { },
  253.   isEditable: function (aRow, aCol) { },
  254.   setCellText: function (aRow, aCol, aValue) { },
  255.   performAction: function (aAction) { },
  256.   performActionOnRow: function (aAction, aRow) { },
  257.   performActionOnCell: function (aAction, aRow, aCol) { },
  258.   getRowProperties: function (aRow, aProperties) { },
  259.   getColumnProperties: function (aCol, aColElt, aProperties) { }
  260.  
  261. };
  262.  
  263.