advanced.js
Go to the documentation of this file.
1 # -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 #
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
9 #
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
14 #
15 # The Original Code is the Firefox Preferences System.
16 #
17 # The Initial Developer of the Original Code is
18 # Ben Goodger.
19 # Portions created by the Initial Developer are Copyright (C) 2005
20 # the Initial Developer. All Rights Reserved.
21 #
22 # Contributor(s):
23 # Ben Goodger <ben@mozilla.org>
24 # Jeff Walden <jwalden+code@mit.edu>
25 #
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
37 #
38 # ***** END LICENSE BLOCK *****
39 
40 // Load DownloadUtils module for convertByteUnits
41 Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
42 
44  _inited: false,
45 
49  init: function ()
50  {
51  this._inited = true;
52  var advancedPrefs = document.getElementById("advancedPrefs");
53 
54  var extraArgs = window.arguments[1];
55  if (extraArgs && extraArgs["advancedTab"]){
56  advancedPrefs.selectedTab = document.getElementById(extraArgs["advancedTab"]);
57  } else {
58  var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
59  if (preference.value !== null)
60  advancedPrefs.selectedIndex = preference.value;
61  }
62 
63 #ifdef MOZ_UPDATER
64  this.updateAppUpdateItems();
65  this.updateAutoItems();
66  this.updateModeItems();
67 #endif
68  this.updateOfflineApps();
69  },
70 
75  tabSelectionChanged: function ()
76  {
77  if (!this._inited)
78  return;
79  var advancedPrefs = document.getElementById("advancedPrefs");
80  var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
81  preference.valueFromPreferences = advancedPrefs.selectedIndex;
82  },
83 
84  // GENERAL TAB
85 
86  /*
87  * Preferences:
88  *
89  * accessibility.browsewithcaret
90  * - true enables keyboard navigation and selection within web pages using a
91  * visible caret, false uses normal keyboard navigation with no caret
92  * accessibility.typeaheadfind
93  * - when set to true, typing outside text areas and input boxes will
94  * automatically start searching for what's typed within the current
95  * document; when set to false, no search action happens
96  * general.autoScroll
97  * - when set to true, clicking the scroll wheel on the mouse activates a
98  * mouse mode where moving the mouse down scrolls the document downward with
99  * speed correlated with the distance of the cursor from the original
100  * position at which the click occurred (and likewise with movement upward);
101  * if false, this behavior is disabled
102  * general.smoothScroll
103  * - set to true to enable finer page scrolling than line-by-line on page-up,
104  * page-down, and other such page movements
105  * layout.spellcheckDefault
106  * - an integer:
107  * 0 disables spellchecking
108  * 1 enables spellchecking, but only for multiline text fields
109  * 2 enables spellchecking for all text fields
110  */
111 
116  _storedSpellCheck: 0,
117 
123  readCheckSpelling: function ()
124  {
125  var pref = document.getElementById("layout.spellcheckDefault");
126  this._storedSpellCheck = pref.value;
127 
128  return (pref.value != 0);
129  },
130 
136  writeCheckSpelling: function ()
137  {
138  var checkbox = document.getElementById("checkSpelling");
139  return checkbox.checked ? (this._storedSpellCheck == 2 ? 2 : 1) : 0;
140  },
141 
142  // NETWORK TAB
143 
144  /*
145  * Preferences:
146  *
147  * browser.cache.disk.capacity
148  * - the size of the browser cache in KB
149  */
150 
154  showConnections: function ()
155  {
156  document.documentElement.openSubDialog("chrome://browser/content/preferences/connection.xul",
157  "", null);
158  },
159 
164  readCacheSize: function ()
165  {
166  var preference = document.getElementById("browser.cache.disk.capacity");
167  return preference.value / 1024;
168  },
169 
174  writeCacheSize: function ()
175  {
176  var cacheSize = document.getElementById("cacheSize");
177  var intValue = parseInt(cacheSize.value, 10);
178  return isNaN(intValue) ? 0 : intValue * 1024;
179  },
180 
184  clearCache: function ()
185  {
186  var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
187  .getService(Components.interfaces.nsICacheService);
188  try {
189  cacheService.evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE);
190  } catch(ex) {}
191  },
192 
193  readOfflineNotify: function()
194  {
195  var pref = document.getElementById("browser.offline-apps.notify");
196  var button = document.getElementById("offlineNotifyExceptions");
197  button.disabled = !pref.value;
198  return pref.value;
199  },
200 
201  showOfflineExceptions: function()
202  {
203  var bundlePreferences = document.getElementById("bundlePreferences");
204  var params = { blockVisible : false,
205  sessionVisible : false,
206  allowVisible : false,
207  prefilledHost : "",
208  permissionType : "offline-app",
209  manageCapability : Components.interfaces.nsIPermissionManager.DENY_ACTION,
210  windowTitle : bundlePreferences.getString("offlinepermissionstitle"),
211  introText : bundlePreferences.getString("offlinepermissionstext") };
212  document.documentElement.openWindow("Browser:Permissions",
213  "chrome://browser/content/preferences/permissions.xul",
214  "", params);
215  },
216 
217  // XXX: duplicated in browser.js
218  _getOfflineAppUsage: function (host, groups)
219  {
220  var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
221  getService(Components.interfaces.nsIApplicationCacheService);
222  if (!groups) {
223  groups = cacheService.getGroups({});
224  }
225  var ios = Components.classes["@mozilla.org/network/io-service;1"].
226  getService(Components.interfaces.nsIIOService);
227 
228  var usage = 0;
229  for (var i = 0; i < groups.length; i++) {
230  var uri = ios.newURI(groups[i], null, null);
231  if (uri.asciiHost == host) {
232  var cache = cacheService.getActiveCache(groups[i]);
233  usage += cache.usage;
234  }
235  }
236 
237  var storageManager = Components.classes["@mozilla.org/dom/storagemanager;1"].
238  getService(Components.interfaces.nsIDOMStorageManager);
239  usage += storageManager.getUsage(host);
240 
241  return usage;
242  },
243 
247  updateOfflineApps: function ()
248  {
249  var pm = Components.classes["@mozilla.org/permissionmanager;1"]
250  .getService(Components.interfaces.nsIPermissionManager);
251 
252  var list = document.getElementById("offlineAppsList");
253  while (list.firstChild) {
254  list.removeChild(list.firstChild);
255  }
256 
257  var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
258  getService(Components.interfaces.nsIApplicationCacheService);
259  var groups = cacheService.getGroups({});
260 
261  var bundle = document.getElementById("bundlePreferences");
262 
263  var enumerator = pm.enumerator;
264  while (enumerator.hasMoreElements()) {
265  var perm = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission);
266  if (perm.type == "offline-app" &&
267  perm.capability != Components.interfaces.nsIPermissionManager.DEFAULT_ACTION &&
268  perm.capability != Components.interfaces.nsIPermissionManager.DENY_ACTION) {
269  var row = document.createElement("listitem");
270  row.id = "";
271  row.className = "offlineapp";
272  row.setAttribute("host", perm.host);
273  var converted = DownloadUtils.
274  convertByteUnits(this._getOfflineAppUsage(perm.host, groups));
275  row.setAttribute("usage",
276  bundle.getFormattedString("offlineAppUsage",
277  converted));
278  list.appendChild(row);
279  }
280  }
281  },
282 
283  offlineAppSelected: function()
284  {
285  var removeButton = document.getElementById("offlineAppsListRemove");
286  var list = document.getElementById("offlineAppsList");
287  if (list.selectedItem) {
288  removeButton.setAttribute("disabled", "false");
289  } else {
290  removeButton.setAttribute("disabled", "true");
291  }
292  },
293 
294  removeOfflineApp: function()
295  {
296  var list = document.getElementById("offlineAppsList");
297  var item = list.selectedItem;
298  var host = item.getAttribute("host");
299 
300  var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
301  .getService(Components.interfaces.nsIPromptService);
302  var flags = prompts.BUTTON_TITLE_IS_STRING * prompts.BUTTON_POS_0 +
303  prompts.BUTTON_TITLE_CANCEL * prompts.BUTTON_POS_1;
304 
305  var bundle = document.getElementById("bundlePreferences");
306  var title = bundle.getString("offlineAppRemoveTitle");
307  var prompt = bundle.getFormattedString("offlineAppRemovePrompt", [host]);
308  var confirm = bundle.getString("offlineAppRemoveConfirm");
309  var result = prompts.confirmEx(window, title, prompt, flags, confirm,
310  null, null, null, {});
311  if (result != 0)
312  return;
313 
314  // clear offline cache entries
315  var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
316  getService(Components.interfaces.nsIApplicationCacheService);
317  var ios = Components.classes["@mozilla.org/network/io-service;1"].
318  getService(Components.interfaces.nsIIOService);
319  var groups = cacheService.getGroups({});
320  for (var i = 0; i < groups.length; i++) {
321  var uri = ios.newURI(groups[i], null, null);
322  if (uri.asciiHost == host) {
323  var cache = cacheService.getActiveCache(groups[i]);
324  cache.discard();
325  }
326  }
327 
328  // send out an offline-app-removed signal. The nsDOMStorage
329  // service will clear DOM storage for this host.
330  var obs = Components.classes["@mozilla.org/observer-service;1"]
331  .getService(Components.interfaces.nsIObserverService);
332  obs.notifyObservers(null, "offline-app-removed", host);
333 
334  // remove the permission
335  var pm = Components.classes["@mozilla.org/permissionmanager;1"]
336  .getService(Components.interfaces.nsIPermissionManager);
337  pm.remove(host, "offline-app",
338  Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
339  pm.remove(host, "offline-app",
340  Components.interfaces.nsIOfflineCacheUpdateService.ALLOW_NO_WARN);
341 
342  list.removeChild(item);
343  gAdvancedPane.offlineAppSelected();
344  },
345 
346  // UPDATE TAB
347 
348  /*
349  * Preferences:
350  *
351  * app.update.enabled
352  * - true if updates to the application are enabled, false otherwise
353  * extensions.update.enabled
354  * - true if updates to extensions and themes are enabled, false otherwise
355  * browser.search.update
356  * - true if updates to search engines are enabled, false otherwise
357  * app.update.auto
358  * - true if updates should be automatically downloaded and installed,
359  * possibly with a warning if incompatible extensions are installed (see
360  * app.update.mode); false if the user should be asked what he wants to do
361  * when an update is available
362  * app.update.mode
363  * - an integer:
364  * 0 do not warn if an update will disable extensions or themes
365  * 1 warn if an update will disable extensions or themes
366  * 2 warn if an update will disable extensions or themes *or* if the
367  * update is a major update
368  */
369 
401 #ifdef MOZ_UPDATER
402  updateAppUpdateItems: function ()
403  {
404  var aus =
405  Components.classes["@mozilla.org/updates/update-service;1"].
406  getService(Components.interfaces.nsIApplicationUpdateService2);
407 
408  var enabledPref = document.getElementById("app.update.enabled");
409  var enableAppUpdate = document.getElementById("enableAppUpdate");
410 
411  enableAppUpdate.disabled = !aus.canCheckForUpdates || enabledPref.locked;
412  },
413 
418  updateAutoItems: function ()
419  {
420  var enabledPref = document.getElementById("app.update.enabled");
421  var autoPref = document.getElementById("app.update.auto");
422 
423  var updateModeLabel = document.getElementById("updateModeLabel");
424  var updateMode = document.getElementById("updateMode");
425 
426  var disable = enabledPref.locked || !enabledPref.value ||
427  autoPref.locked;
428  updateModeLabel.disabled = updateMode.disabled = disable;
429  },
430 
435  updateModeItems: function ()
436  {
437  var enabledPref = document.getElementById("app.update.enabled");
438  var autoPref = document.getElementById("app.update.auto");
439  var modePref = document.getElementById("app.update.mode");
440 
441  var warnIncompatible = document.getElementById("warnIncompatible");
442 
443  var disable = enabledPref.locked || !enabledPref.value || autoPref.locked ||
444  !autoPref.value || modePref.locked;
445  warnIncompatible.disabled = disable;
446  },
447 
455  _modePreference: -1,
456 
470  readAddonWarn: function ()
471  {
472  var preference = document.getElementById("app.update.mode");
473  var doNotWarn = preference.value != 0;
474  gAdvancedPane._modePreference = doNotWarn ? preference.value : 1;
475  return doNotWarn;
476  },
477 
483  writeAddonWarn: function ()
484  {
485  var warnIncompatible = document.getElementById("warnIncompatible");
486  return !warnIncompatible.checked ? 0 : gAdvancedPane._modePreference;
487  },
488 
492  showUpdates: function ()
493  {
494  var prompter = Components.classes["@mozilla.org/updates/update-prompt;1"]
495  .createInstance(Components.interfaces.nsIUpdatePrompt);
496  prompter.showUpdateHistory(window);
497  },
498 #endif
499 
504  updateAddonUpdateUI: function ()
505  {
506  var enabledPref = document.getElementById("extensions.update.enabled");
507  var enableAddonUpdate = document.getElementById("enableAddonUpdate");
508 
509  enableAddonUpdate.disabled = enabledPref.locked;
510  },
511 
512  // ENCRYPTION TAB
513 
514  /*
515  * Preferences:
516  *
517  * security.enable_ssl3
518  * - true if SSL 3 encryption is enabled, false otherwise
519  * security.enable_tls
520  * - true if TLS encryption is enabled, false otherwise
521  * security.default_personal_cert
522  * - a string:
523  * "Select Automatically" select a certificate automatically when a site
524  * requests one
525  * "Ask Every Time" present a dialog to the user so he can select
526  * the certificate to use on a site which
527  * requests one
528  */
529 
533  showCertificates: function ()
534  {
535  document.documentElement.openWindow("mozilla:certmanager",
536  "chrome://pippki/content/certManager.xul",
537  "", null);
538  },
539 
543  showCRLs: function ()
544  {
545  document.documentElement.openWindow("mozilla:crlmanager",
546  "chrome://pippki/content/crlManager.xul",
547  "", null);
548  },
549 
553  showOCSP: function ()
554  {
555  document.documentElement.openSubDialog("chrome://mozapps/content/preferences/ocsp.xul",
556  "", null);
557  },
558 
562  showSecurityDevices: function ()
563  {
564  document.documentElement.openWindow("mozilla:devicemanager",
565  "chrome://pippki/content/device_manager.xul",
566  "", null);
567  }
568 #ifdef HAVE_SHELL_SERVICE
569  ,
570 
571  // SYSTEM DEFAULTS
572 
573  /*
574  * Preferences:
575  *
576  * browser.shell.checkDefault
577  * - true if a default-browser check (and prompt to make it so if necessary)
578  * occurs at startup, false otherwise
579  */
580 
587  checkNow: function ()
588  {
589  var shellSvc = Components.classes["@mozilla.org/browser/shell-service;1"]
590  .getService(Components.interfaces.nsIShellService);
591  var brandBundle = document.getElementById("bundleBrand");
592  var shellBundle = document.getElementById("bundleShell");
593  var brandShortName = brandBundle.getString("brandShortName");
594  var promptTitle = shellBundle.getString("setDefaultBrowserTitle");
595  var promptMessage;
596  const IPS = Components.interfaces.nsIPromptService;
597  var psvc = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
598  .getService(IPS);
599  if (!shellSvc.isDefaultBrowser(false)) {
600  promptMessage = shellBundle.getFormattedString("setDefaultBrowserMessage",
601  [brandShortName]);
602  var rv = psvc.confirmEx(window, promptTitle, promptMessage,
603  IPS.STD_YES_NO_BUTTONS,
604  null, null, null, null, { });
605  if (rv == 0)
606  shellSvc.setDefaultBrowser(true, false);
607  }
608  else {
609  promptMessage = shellBundle.getFormattedString("alreadyDefaultBrowser",
610  [brandShortName]);
611  psvc.alert(window, promptTitle, promptMessage);
612  }
613  }
614 #endif
615 };
function convertByteUnits(aBytes)
Definition: FeedWriter.js:168
var pref
Definition: openLocation.js:44
sbDeviceFirmwareAutoCheckForUpdate prototype flags
var gAdvancedPane
Definition: advanced.js:43
getService(Ci.sbIFaceplateManager)
let window
_window init
Definition: FeedWriter.js:1144
inst settings prompt
var bundle
return null
Definition: FeedWriter.js:1143
const cacheService
Definition: pageInfo.js:195
var uri
Definition: FeedWriter.js:1135
var ios
Definition: head_feeds.js:5
_getSelectedPageStyle s i
var brandBundle
Definition: xpInstallHat.js:37