home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / firefox-3.0.14 / chrome / browser.jar / content / browser / preferences / advanced.js < prev    next >
Encoding:
Text File  |  2009-09-07  |  20.4 KB  |  557 lines

  1. //@line 39 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/preferences/advanced.js"
  2.  
  3. // Load DownloadUtils module for convertByteUnits
  4. Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
  5.  
  6. var gAdvancedPane = {
  7.   _inited: false,
  8.  
  9.   /**
  10.    * Brings the appropriate tab to the front and initializes various bits of UI.
  11.    */
  12.   init: function ()
  13.   {
  14.     this._inited = true;
  15.     var advancedPrefs = document.getElementById("advancedPrefs");
  16.  
  17.     var extraArgs = window.arguments[1];
  18.     if (extraArgs && extraArgs["advancedTab"]){
  19.       advancedPrefs.selectedTab = document.getElementById(extraArgs["advancedTab"]);
  20.     } else {
  21.       var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
  22.       if (preference.value === null)
  23.         return;
  24.       advancedPrefs.selectedIndex = preference.value;
  25.     }
  26.  
  27.     this.updateAppUpdateItems();
  28.     this.updateAutoItems();
  29.     this.updateModeItems();
  30.     this.updateOfflineApps();
  31.   },
  32.  
  33.   /**
  34.    * Stores the identity of the current tab in preferences so that the selected
  35.    * tab can be persisted between openings of the preferences window.
  36.    */
  37.   tabSelectionChanged: function ()
  38.   {
  39.     if (!this._inited)
  40.       return;
  41.     var advancedPrefs = document.getElementById("advancedPrefs");
  42.     var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
  43.     preference.valueFromPreferences = advancedPrefs.selectedIndex;
  44.   },
  45.   
  46.   // GENERAL TAB
  47.  
  48.   /*
  49.    * Preferences:
  50.    *
  51.    * accessibility.browsewithcaret
  52.    * - true enables keyboard navigation and selection within web pages using a
  53.    *   visible caret, false uses normal keyboard navigation with no caret
  54.    * accessibility.typeaheadfind
  55.    * - when set to true, typing outside text areas and input boxes will
  56.    *   automatically start searching for what's typed within the current
  57.    *   document; when set to false, no search action happens
  58.    * general.autoScroll
  59.    * - when set to true, clicking the scroll wheel on the mouse activates a
  60.    *   mouse mode where moving the mouse down scrolls the document downward with
  61.    *   speed correlated with the distance of the cursor from the original
  62.    *   position at which the click occurred (and likewise with movement upward);
  63.    *   if false, this behavior is disabled
  64.    * general.smoothScroll
  65.    * - set to true to enable finer page scrolling than line-by-line on page-up,
  66.    *   page-down, and other such page movements
  67.    * layout.spellcheckDefault
  68.    * - an integer:
  69.    *     0  disables spellchecking
  70.    *     1  enables spellchecking, but only for multiline text fields
  71.    *     2  enables spellchecking for all text fields
  72.    */
  73.  
  74.   /**
  75.    * Stores the original value of the spellchecking preference to enable proper
  76.    * restoration if unchanged (since we're mapping a tristate onto a checkbox).
  77.    */
  78.   _storedSpellCheck: 0,
  79.  
  80.   /**
  81.    * Returns true if any spellchecking is enabled and false otherwise, caching
  82.    * the current value to enable proper pref restoration if the checkbox is
  83.    * never changed.
  84.    */
  85.   readCheckSpelling: function ()
  86.   {
  87.     var pref = document.getElementById("layout.spellcheckDefault");
  88.     this._storedSpellCheck = pref.value;
  89.  
  90.     return (pref.value != 0);
  91.   },
  92.  
  93.   /**
  94.    * Returns the value of the spellchecking preference represented by UI,
  95.    * preserving the preference's "hidden" value if the preference is
  96.    * unchanged and represents a value not strictly allowed in UI.
  97.    */
  98.   writeCheckSpelling: function ()
  99.   {
  100.     var checkbox = document.getElementById("checkSpelling");
  101.     return checkbox.checked ? (this._storedSpellCheck == 2 ? 2 : 1) : 0;
  102.   },
  103.  
  104.   // NETWORK TAB
  105.  
  106.   /*
  107.    * Preferences:
  108.    *
  109.    * browser.cache.disk.capacity
  110.    * - the size of the browser cache in KB
  111.    */
  112.  
  113.   /**
  114.    * Displays a dialog in which proxy settings may be changed.
  115.    */
  116.   showConnections: function ()
  117.   {
  118.     document.documentElement.openSubDialog("chrome://browser/content/preferences/connection.xul",
  119.                                            "", null);
  120.   },
  121.  
  122.   /**
  123.    * Converts the cache size from units of KB to units of MB and returns that
  124.    * value.
  125.    */
  126.   readCacheSize: function ()
  127.   {
  128.     var preference = document.getElementById("browser.cache.disk.capacity");
  129.     return preference.value / 1000;
  130.   },
  131.  
  132.   /**
  133.    * Converts the cache size as specified in UI (in MB) to KB and returns that
  134.    * value.
  135.    */
  136.   writeCacheSize: function ()
  137.   {
  138.     var cacheSize = document.getElementById("cacheSize");
  139.     var intValue = parseInt(cacheSize.value, 10);
  140.     return isNaN(intValue) ? 0 : intValue * 1000;
  141.   },
  142.  
  143.   /**
  144.    * Clears the cache.
  145.    */
  146.   clearCache: function ()
  147.   {
  148.     var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
  149.                                     .getService(Components.interfaces.nsICacheService);
  150.     try {
  151.       cacheService.evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE);
  152.     } catch(ex) {}
  153.   },
  154.  
  155.   readOfflineNotify: function()
  156.   {
  157.     var pref = document.getElementById("browser.offline-apps.notify");
  158.     var button = document.getElementById("offlineNotifyExceptions");
  159.     button.disabled = !pref.value;
  160.     return pref.value;
  161.   },
  162.  
  163.   showOfflineExceptions: function()
  164.   {
  165.     var bundlePreferences = document.getElementById("bundlePreferences");
  166.     var params = { blockVisible     : false,
  167.                    sessionVisible   : false,
  168.                    allowVisible     : false,
  169.                    prefilledHost    : "",
  170.                    permissionType   : "offline-app",
  171.                    manageCapability : Components.interfaces.nsIPermissionManager.DENY_ACTION,
  172.                    windowTitle      : bundlePreferences.getString("offlinepermissionstitle"),
  173.                    introText        : bundlePreferences.getString("offlinepermissionstext") };
  174.     document.documentElement.openWindow("Browser:Permissions",
  175.                                         "chrome://browser/content/preferences/permissions.xul",
  176.                                         "", params);
  177.   },
  178.  
  179.   // XXX: duplicated in browser.js
  180.   _getOfflineAppUsage: function (host)
  181.   {
  182.     var cacheService = Components.classes["@mozilla.org/network/cache-service;1"].
  183.                        getService(Components.interfaces.nsICacheService);
  184.     var cacheSession = cacheService.createSession("HTTP-offline",
  185.                                                   Components.interfaces.nsICache.STORE_OFFLINE,
  186.                                                   true).
  187.                        QueryInterface(Components.interfaces.nsIOfflineCacheSession);
  188.     var usage = cacheSession.getDomainUsage(host);
  189.  
  190.     var storageManager = Components.classes["@mozilla.org/dom/storagemanager;1"].
  191.                          getService(Components.interfaces.nsIDOMStorageManager);
  192.     usage += storageManager.getUsage(host);
  193.  
  194.     return usage;
  195.   },
  196.  
  197.   /**
  198.    * Updates the list of offline applications
  199.    */
  200.   updateOfflineApps: function ()
  201.   {
  202.     var pm = Components.classes["@mozilla.org/permissionmanager;1"]
  203.                        .getService(Components.interfaces.nsIPermissionManager);
  204.  
  205.     var list = document.getElementById("offlineAppsList");
  206.     while (list.firstChild) {
  207.       list.removeChild(list.firstChild);
  208.     }
  209.  
  210.     var bundle = document.getElementById("bundlePreferences");
  211.  
  212.     var enumerator = pm.enumerator;
  213.     while (enumerator.hasMoreElements()) {
  214.       var perm = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission);
  215.       if (perm.type == "offline-app" &&
  216.           perm.capability != Components.interfaces.nsIPermissionManager.DEFAULT_ACTION &&
  217.           perm.capability != Components.interfaces.nsIPermissionManager.DENY_ACTION) {
  218.         var row = document.createElement("listitem");
  219.         row.id = "";
  220.         row.className = "offlineapp";
  221.         row.setAttribute("host", perm.host);
  222.         var converted = DownloadUtils.
  223.                         convertByteUnits(this._getOfflineAppUsage(perm.host));
  224.         row.setAttribute("usage",
  225.                          bundle.getFormattedString("offlineAppUsage",
  226.                                                    converted));
  227.         list.appendChild(row);
  228.       }
  229.     }
  230.   },
  231.  
  232.   offlineAppSelected: function()
  233.   {
  234.     var removeButton = document.getElementById("offlineAppsListRemove");
  235.     var list = document.getElementById("offlineAppsList");
  236.     if (list.selectedItem) {
  237.       removeButton.setAttribute("disabled", "false");
  238.     } else {
  239.       removeButton.setAttribute("disabled", "true");
  240.     }
  241.   },
  242.  
  243.   removeOfflineApp: function()
  244.   {
  245.     var list = document.getElementById("offlineAppsList");
  246.     var item = list.selectedItem;
  247.     var host = item.getAttribute("host");
  248.  
  249.     var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  250.                             .getService(Components.interfaces.nsIPromptService);
  251.     var flags = prompts.BUTTON_TITLE_IS_STRING * prompts.BUTTON_POS_0 +
  252.                 prompts.BUTTON_TITLE_CANCEL * prompts.BUTTON_POS_1;
  253.  
  254.     var bundle = document.getElementById("bundlePreferences");
  255.     var title = bundle.getString("offlineAppRemoveTitle");
  256.     var prompt = bundle.getFormattedString("offlineAppRemovePrompt", [host]);
  257.     var confirm = bundle.getString("offlineAppRemoveConfirm");
  258.     var result = prompts.confirmEx(window, title, prompt, flags, confirm,
  259.                                    null, null, null, {});
  260.     if (result != 0)
  261.       return;
  262.  
  263.     // clear offline cache entries
  264.     var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
  265.                        .getService(Components.interfaces.nsICacheService);
  266.     var cacheSession = cacheService.createSession("HTTP-offline",
  267.                                                   Components.interfaces.nsICache.STORE_OFFLINE,
  268.                                                   true)
  269.                        .QueryInterface(Components.interfaces.nsIOfflineCacheSession);
  270.     cacheSession.clearKeysOwnedByDomain(host);
  271.     cacheSession.evictUnownedEntries();
  272.  
  273.     // send out an offline-app-removed signal.  The nsDOMStorage
  274.     // service will clear DOM storage for this host.
  275.     var obs = Components.classes["@mozilla.org/observer-service;1"]
  276.                         .getService(Components.interfaces.nsIObserverService);
  277.     obs.notifyObservers(null, "offline-app-removed", host);
  278.  
  279.     // remove the permission
  280.     var pm = Components.classes["@mozilla.org/permissionmanager;1"]
  281.                        .getService(Components.interfaces.nsIPermissionManager);
  282.     pm.remove(host, "offline-app",
  283.               Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
  284.     pm.remove(host, "offline-app",
  285.               Components.interfaces.nsIOfflineCacheUpdateService.ALLOW_NO_WARN);
  286.  
  287.     list.removeChild(item);
  288.     gAdvancedPane.offlineAppSelected();
  289.   },
  290.  
  291.   // UPDATE TAB
  292.  
  293.   /*
  294.    * Preferences:
  295.    *
  296.    * app.update.enabled
  297.    * - true if updates to the application are enabled, false otherwise
  298.    * extensions.update.enabled
  299.    * - true if updates to extensions and themes are enabled, false otherwise
  300.    * browser.search.update
  301.    * - true if updates to search engines are enabled, false otherwise
  302.    * app.update.auto
  303.    * - true if updates should be automatically downloaded and installed,
  304.    *   possibly with a warning if incompatible extensions are installed (see
  305.    *   app.update.mode); false if the user should be asked what he wants to do
  306.    *   when an update is available
  307.    * app.update.mode
  308.    * - an integer:
  309.    *     0    do not warn if an update will disable extensions or themes
  310.    *     1    warn if an update will disable extensions or themes
  311.    *     2    warn if an update will disable extensions or themes *or* if the
  312.    *          update is a major update
  313.    */
  314.  
  315.   /**
  316.    * Enables and disables various UI preferences as necessary to reflect locked,
  317.    * disabled, and checked/unchecked states.
  318.    *
  319.    * UI state matrix for update preference conditions
  320.    * 
  321.    * UI Components:                                     Preferences
  322.    * 1 = Firefox checkbox                               i   = app.update.enabled
  323.    * 2 = When updates for Firefox are found label       ii  = app.update.auto
  324.    * 3 = Automatic Radiogroup (Ask vs. Automatically)   iii = app.update.mode
  325.    * 4 = Warn before disabling extensions checkbox
  326.    * 
  327.    * States:
  328.    * Element     p   val     locked    Disabled 
  329.    * 1           i   t/f     f         false
  330.    *             i   t/f     t         true
  331.    *             ii  t/f     t/f       false
  332.    *             iii 0/1/2   t/f       false
  333.    * 2,3         i   t       t/f       false
  334.    *             i   f       t/f       true
  335.    *             ii  t/f     f         false
  336.    *             ii  t/f     t         true
  337.    *             iii 0/1/2   t/f       false
  338.    * 4           i   t       t/f       false
  339.    *             i   f       t/f       true
  340.    *             ii  t       t/f       false
  341.    *             ii  f       t/f       true
  342.    *             iii 0/1/2   f         false
  343.    *             iii 0/1/2   t         true   
  344.    * 
  345.    */
  346.   updateAppUpdateItems: function () 
  347.   {
  348.     var aus = 
  349.         Components.classes["@mozilla.org/updates/update-service;1"].
  350.         getService(Components.interfaces.nsIApplicationUpdateService);
  351.  
  352.     var enabledPref = document.getElementById("app.update.enabled");
  353.     var enableAppUpdate = document.getElementById("enableAppUpdate");
  354.  
  355.     enableAppUpdate.disabled = true;
  356.   },
  357.  
  358.   /**
  359.    * Enables/disables UI for "when updates are found" based on the values,
  360.    * and "locked" states of associated preferences.
  361.    */
  362.   updateAutoItems: function () 
  363.   {
  364.     var enabledPref = document.getElementById("app.update.enabled");
  365.     var autoPref = document.getElementById("app.update.auto");
  366.     
  367.     var updateModeLabel = document.getElementById("updateModeLabel");
  368.     var updateMode = document.getElementById("updateMode");
  369.     
  370.     var disable = true;
  371.     updateModeLabel.disabled = updateMode.disabled = disable;
  372.   },
  373.  
  374.   /**
  375.    * Enables/disables the "warn if incompatible extensions/themes exist" UI
  376.    * based on the values and "locked" states of various preferences.
  377.    */
  378.   updateModeItems: function () 
  379.   {
  380.     var enabledPref = document.getElementById("app.update.enabled");
  381.     var autoPref = document.getElementById("app.update.auto");
  382.     var modePref = document.getElementById("app.update.mode");
  383.     
  384.     var warnIncompatible = document.getElementById("warnIncompatible");
  385.     
  386.     var disable = true;
  387.     warnIncompatible.disabled = disable;
  388.   },
  389.  
  390.   /**
  391.    * The Extensions checkbox and button are disabled only if the enable Addon
  392.    * update preference is locked. 
  393.    */
  394.   updateAddonUpdateUI: function ()
  395.   {
  396.     var enabledPref = document.getElementById("extensions.update.enabled");
  397.     var enableAddonUpdate = document.getElementById("enableAddonUpdate");
  398.  
  399.     enableAddonUpdate.disabled = enabledPref.locked;
  400.   },  
  401.  
  402.   /**
  403.    * Stores the value of the app.update.mode preference, which is a tristate
  404.    * integer preference.  We store the value here so that we can properly
  405.    * restore the preference value if the UI reflecting the preference value
  406.    * is in a state which can represent either of two integer values (as
  407.    * opposed to only one possible value in the other UI state).
  408.    */
  409.   _modePreference: -1,
  410.  
  411.   /**
  412.    * Reads the app.update.mode preference and converts its value into a
  413.    * true/false value for use in determining whether the "Warn me if this will
  414.    * disable extensions or themes" checkbox is checked.  We also save the value
  415.    * of the preference so that the preference value can be properly restored if
  416.    * the user's preferences cannot adequately be expressed by a single checkbox.
  417.    *
  418.    * app.update.modee         Checkbox State    Meaning
  419.    * 0                        Unchecked         Do not warn
  420.    * 1                        Checked           Warn if there are incompatibilities
  421.    * 2                        Checked           Warn if there are incompatibilities,
  422.    *                                            or the update is major.
  423.    */
  424.   readAddonWarn: function ()
  425.   {
  426.     var preference = document.getElementById("app.update.mode");
  427.     var doNotWarn = preference.value != 0;
  428.     gAdvancedPane._modePreference = doNotWarn ? preference.value : 1;
  429.     return doNotWarn;
  430.   },
  431.  
  432.   /**
  433.    * Converts the state of the "Warn me if this will disable extensions or
  434.    * themes" checkbox into the integer preference which represents it,
  435.    * returning that value.
  436.    */
  437.   writeAddonWarn: function ()
  438.   {
  439.     var warnIncompatible = document.getElementById("warnIncompatible");
  440.     return !warnIncompatible.checked ? 0 : gAdvancedPane._modePreference;
  441.   },
  442.  
  443.   /**
  444.    * Displays the history of installed updates.
  445.    */
  446.   showUpdates: function ()
  447.   {
  448.     var prompter = Components.classes["@mozilla.org/updates/update-prompt;1"]
  449.                              .createInstance(Components.interfaces.nsIUpdatePrompt);
  450.     prompter.showUpdateHistory(window);
  451.   },
  452.   
  453.   // ENCRYPTION TAB
  454.  
  455.   /*
  456.    * Preferences:
  457.    *
  458.    * security.enable_ssl3
  459.    * - true if SSL 3 encryption is enabled, false otherwise
  460.    * security.enable_tls
  461.    * - true if TLS encryption is enabled, false otherwise
  462.    * security.default_personal_cert
  463.    * - a string:
  464.    *     "Select Automatically"   select a certificate automatically when a site
  465.    *                              requests one
  466.    *     "Ask Every Time"         present a dialog to the user so he can select
  467.    *                              the certificate to use on a site which
  468.    *                              requests one
  469.    */
  470.  
  471.   /**
  472.    * Displays the user's certificates and associated options.
  473.    */
  474.   showCertificates: function ()
  475.   {
  476.     document.documentElement.openWindow("mozilla:certmanager",
  477.                                         "chrome://pippki/content/certManager.xul",
  478.                                         "", null);
  479.   },
  480.  
  481.   /**
  482.    * Displays a dialog which describes the user's CRLs.
  483.    */
  484.   showCRLs: function ()
  485.   {
  486.     document.documentElement.openWindow("Mozilla:CRLManager", 
  487.                                         "chrome://pippki/content/crlManager.xul",
  488.                                         "", null);
  489.   },
  490.  
  491.   /**
  492.    * Displays a dialog in which OCSP preferences can be configured.
  493.    */
  494.   showOCSP: function ()
  495.   {
  496.     document.documentElement.openSubDialog("chrome://mozapps/content/preferences/ocsp.xul",
  497.                                            "", null);
  498.   },
  499.  
  500.   /**
  501.    * Displays a dialog from which the user can manage his security devices.
  502.    */
  503.   showSecurityDevices: function ()
  504.   {
  505.     document.documentElement.openWindow("mozilla:devicemanager",
  506.                                         "chrome://pippki/content/device_manager.xul",
  507.                                         "", null);
  508.   }
  509. //@line 547 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/preferences/advanced.js"
  510.   ,
  511.  
  512.   // SYSTEM DEFAULTS
  513.  
  514.   /*
  515.    * Preferences:
  516.    *
  517.    * browser.shell.checkDefault
  518.    * - true if a default-browser check (and prompt to make it so if necessary)
  519.    *   occurs at startup, false otherwise
  520.    */
  521.  
  522.   /**
  523.    * Checks whether the browser is currently registered with the operating
  524.    * system as the default browser.  If the browser is not currently the
  525.    * default browser, the user is given the option of making it the default;
  526.    * otherwise, the user is informed that this browser already is the browser.
  527.    */
  528.   checkNow: function ()
  529.   {
  530.     var shellSvc = Components.classes["@mozilla.org/browser/shell-service;1"]
  531.                              .getService(Components.interfaces.nsIShellService);
  532.     var brandBundle = document.getElementById("bundleBrand");
  533.     var shellBundle = document.getElementById("bundleShell");
  534.     var brandShortName = brandBundle.getString("brandShortName");
  535.     var promptTitle = shellBundle.getString("setDefaultBrowserTitle");
  536.     var promptMessage;
  537.     const IPS = Components.interfaces.nsIPromptService;
  538.     var psvc = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  539.                          .getService(IPS);
  540.     if (!shellSvc.isDefaultBrowser(false)) {
  541.       promptMessage = shellBundle.getFormattedString("setDefaultBrowserMessage", 
  542.                                                      [brandShortName]);
  543.       var rv = psvc.confirmEx(window, promptTitle, promptMessage, 
  544.                               IPS.STD_YES_NO_BUTTONS,
  545.                               null, null, null, null, { });
  546.       if (rv == 0)
  547.         shellSvc.setDefaultBrowser(true, false);
  548.     }
  549.     else {
  550.       promptMessage = shellBundle.getFormattedString("alreadyDefaultBrowser",
  551.                                                      [brandShortName]);
  552.       psvc.alert(window, promptTitle, promptMessage);
  553.     }
  554.   }
  555. //@line 593 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/preferences/advanced.js"
  556. };
  557.