Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // Load DownloadUtils module for convertByteUnits
6 Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
7 Components.utils.import("resource://gre/modules/LoadContextInfo.jsm");
8 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
10 var gAdvancedPane = {
11 _inited: false,
13 /**
14 * Brings the appropriate tab to the front and initializes various bits of UI.
15 */
16 init: function ()
17 {
18 this._inited = true;
19 var advancedPrefs = document.getElementById("advancedPrefs");
21 var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
22 if (preference.value !== null)
23 advancedPrefs.selectedIndex = preference.value;
25 #ifdef HAVE_SHELL_SERVICE
26 this.updateSetDefaultBrowser();
27 #ifdef XP_WIN
28 // In Windows 8 we launch the control panel since it's the only
29 // way to get all file type association prefs. So we don't know
30 // when the user will select the default. We refresh here periodically
31 // in case the default changes. On other Windows OS's defaults can also
32 // be set while the prefs are open.
33 window.setInterval(this.updateSetDefaultBrowser, 1000);
35 #ifdef MOZ_METRO
36 // Pre Windows 8, we should hide the update related settings
37 // for the Metro browser
38 let version = Components.classes["@mozilla.org/system-info;1"].
39 getService(Components.interfaces.nsIPropertyBag2).
40 getProperty("version");
41 let preWin8 = parseFloat(version) < 6.2;
42 this._showingWin8Prefs = !preWin8;
43 if (preWin8) {
44 ["autoMetro", "autoMetroIndent"].forEach(
45 function(id) document.getElementById(id).collapsed = true
46 );
47 } else {
48 let brandShortName =
49 document.getElementById("bundleBrand").getString("brandShortName");
50 let bundlePrefs = document.getElementById("bundlePreferences");
51 let autoDesktop = document.getElementById("autoDesktop");
52 autoDesktop.label =
53 bundlePrefs.getFormattedString("updateAutoDesktop.label",
54 [brandShortName]);
55 autoDesktop.accessKey =
56 bundlePrefs.getString("updateAutoDesktop.accessKey");
57 }
58 #endif
59 #endif
60 #endif
61 #ifdef MOZ_UPDATER
62 this.updateReadPrefs();
63 #endif
64 this.updateOfflineApps();
65 #ifdef MOZ_CRASHREPORTER
66 this.initSubmitCrashes();
67 #endif
68 this.initTelemetry();
69 #ifdef MOZ_SERVICES_HEALTHREPORT
70 this.initSubmitHealthReport();
71 #endif
72 this.updateActualCacheSize();
73 this.updateActualAppCacheSize();
74 },
76 /**
77 * Stores the identity of the current tab in preferences so that the selected
78 * tab can be persisted between openings of the preferences window.
79 */
80 tabSelectionChanged: function ()
81 {
82 if (!this._inited)
83 return;
84 var advancedPrefs = document.getElementById("advancedPrefs");
85 var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
86 preference.valueFromPreferences = advancedPrefs.selectedIndex;
87 },
89 // GENERAL TAB
91 /*
92 * Preferences:
93 *
94 * accessibility.browsewithcaret
95 * - true enables keyboard navigation and selection within web pages using a
96 * visible caret, false uses normal keyboard navigation with no caret
97 * accessibility.typeaheadfind
98 * - when set to true, typing outside text areas and input boxes will
99 * automatically start searching for what's typed within the current
100 * document; when set to false, no search action happens
101 * general.autoScroll
102 * - when set to true, clicking the scroll wheel on the mouse activates a
103 * mouse mode where moving the mouse down scrolls the document downward with
104 * speed correlated with the distance of the cursor from the original
105 * position at which the click occurred (and likewise with movement upward);
106 * if false, this behavior is disabled
107 * general.smoothScroll
108 * - set to true to enable finer page scrolling than line-by-line on page-up,
109 * page-down, and other such page movements
110 * layout.spellcheckDefault
111 * - an integer:
112 * 0 disables spellchecking
113 * 1 enables spellchecking, but only for multiline text fields
114 * 2 enables spellchecking for all text fields
115 */
117 /**
118 * Stores the original value of the spellchecking preference to enable proper
119 * restoration if unchanged (since we're mapping a tristate onto a checkbox).
120 */
121 _storedSpellCheck: 0,
123 /**
124 * Returns true if any spellchecking is enabled and false otherwise, caching
125 * the current value to enable proper pref restoration if the checkbox is
126 * never changed.
127 */
128 readCheckSpelling: function ()
129 {
130 var pref = document.getElementById("layout.spellcheckDefault");
131 this._storedSpellCheck = pref.value;
133 return (pref.value != 0);
134 },
136 /**
137 * Returns the value of the spellchecking preference represented by UI,
138 * preserving the preference's "hidden" value if the preference is
139 * unchanged and represents a value not strictly allowed in UI.
140 */
141 writeCheckSpelling: function ()
142 {
143 var checkbox = document.getElementById("checkSpelling");
144 return checkbox.checked ? (this._storedSpellCheck == 2 ? 2 : 1) : 0;
145 },
148 /**
149 * When the user toggles the layers.acceleration.disabled pref,
150 * sync its new value to the gfx.direct2d.disabled pref too.
151 */
152 updateHardwareAcceleration: function()
153 {
154 #ifdef XP_WIN
155 var fromPref = document.getElementById("layers.acceleration.disabled");
156 var toPref = document.getElementById("gfx.direct2d.disabled");
157 toPref.value = fromPref.value;
158 #endif
159 },
161 // DATA CHOICES TAB
163 /**
164 * Set up or hide the Learn More links for various data collection options
165 */
166 _setupLearnMoreLink: function (pref, element) {
167 // set up the Learn More link with the correct URL
168 let url = Services.prefs.getCharPref(pref);
169 let el = document.getElementById(element);
171 if (url) {
172 el.setAttribute("href", url);
173 } else {
174 el.setAttribute("hidden", "true");
175 }
176 },
178 /**
179 *
180 */
181 initSubmitCrashes: function ()
182 {
183 this._setupLearnMoreLink("toolkit.crashreporter.infoURL",
184 "crashReporterLearnMore");
186 var checkbox = document.getElementById("submitCrashesBox");
187 try {
188 var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"].
189 getService(Components.interfaces.nsICrashReporter);
190 checkbox.checked = cr.submitReports;
191 } catch (e) {
192 checkbox.style.display = "none";
193 }
194 },
196 /**
197 *
198 */
199 updateSubmitCrashes: function ()
200 {
201 var checkbox = document.getElementById("submitCrashesBox");
202 try {
203 var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"].
204 getService(Components.interfaces.nsICrashReporter);
205 cr.submitReports = checkbox.checked;
206 } catch (e) { }
207 },
209 /**
210 * The preference/checkbox is configured in XUL.
211 *
212 * In all cases, set up the Learn More link sanely.
213 */
214 initTelemetry: function ()
215 {
216 #ifdef MOZ_TELEMETRY_REPORTING
217 this._setupLearnMoreLink("toolkit.telemetry.infoURL", "telemetryLearnMore");
218 #endif
219 },
221 #ifdef MOZ_SERVICES_HEALTHREPORT
222 /**
223 * Initialize the health report service reference and checkbox.
224 */
225 initSubmitHealthReport: function () {
226 this._setupLearnMoreLink("datareporting.healthreport.infoURL", "FHRLearnMore");
228 let policy = Components.classes["@mozilla.org/datareporting/service;1"]
229 .getService(Components.interfaces.nsISupports)
230 .wrappedJSObject
231 .policy;
233 let checkbox = document.getElementById("submitHealthReportBox");
235 if (!policy || policy.healthReportUploadLocked) {
236 checkbox.setAttribute("disabled", "true");
237 return;
238 }
240 checkbox.checked = policy.healthReportUploadEnabled;
241 },
243 /**
244 * Update the health report policy acceptance with state from checkbox.
245 */
246 updateSubmitHealthReport: function () {
247 let policy = Components.classes["@mozilla.org/datareporting/service;1"]
248 .getService(Components.interfaces.nsISupports)
249 .wrappedJSObject
250 .policy;
252 if (!policy) {
253 return;
254 }
256 let checkbox = document.getElementById("submitHealthReportBox");
257 policy.recordHealthReportUploadEnabled(checkbox.checked,
258 "Checkbox from preferences pane");
259 },
260 #endif
262 // NETWORK TAB
264 /*
265 * Preferences:
266 *
267 * browser.cache.disk.capacity
268 * - the size of the browser cache in KB
269 * - Only used if browser.cache.disk.smart_size.enabled is disabled
270 */
272 /**
273 * Displays a dialog in which proxy settings may be changed.
274 */
275 showConnections: function ()
276 {
277 openDialog("chrome://browser/content/preferences/connection.xul",
278 "mozilla:connectionmanager",
279 "modal=yes",
280 null);
281 },
283 // Retrieves the amount of space currently used by disk cache
284 updateActualCacheSize: function ()
285 {
286 var actualSizeLabel = document.getElementById("actualDiskCacheSize");
287 var prefStrBundle = document.getElementById("bundlePreferences");
289 // Needs to root the observer since cache service keeps only a weak reference.
290 this.observer = {
291 onNetworkCacheDiskConsumption: function(consumption) {
292 var size = DownloadUtils.convertByteUnits(consumption);
293 actualSizeLabel.value = prefStrBundle.getFormattedString("actualDiskCacheSize", size);
294 },
296 QueryInterface: XPCOMUtils.generateQI([
297 Components.interfaces.nsICacheStorageConsumptionObserver,
298 Components.interfaces.nsISupportsWeakReference
299 ])
300 };
302 actualSizeLabel.value = prefStrBundle.getString("actualDiskCacheSizeCalculated");
304 var cacheService =
305 Components.classes["@mozilla.org/netwerk/cache-storage-service;1"]
306 .getService(Components.interfaces.nsICacheStorageService);
307 cacheService.asyncGetDiskConsumption(this.observer);
308 },
310 // Retrieves the amount of space currently used by offline cache
311 updateActualAppCacheSize: function ()
312 {
313 var visitor = {
314 visitDevice: function (deviceID, deviceInfo)
315 {
316 if (deviceID == "offline") {
317 var actualSizeLabel = document.getElementById("actualAppCacheSize");
318 var sizeStrings = DownloadUtils.convertByteUnits(deviceInfo.totalSize);
319 var prefStrBundle = document.getElementById("bundlePreferences");
320 var sizeStr = prefStrBundle.getFormattedString("actualAppCacheSize", sizeStrings);
321 actualSizeLabel.value = sizeStr;
322 }
323 // Do not enumerate entries
324 return false;
325 },
327 visitEntry: function (deviceID, entryInfo)
328 {
329 // Do not enumerate entries.
330 return false;
331 }
332 };
334 var cacheService =
335 Components.classes["@mozilla.org/network/cache-service;1"]
336 .getService(Components.interfaces.nsICacheService);
337 cacheService.visitEntries(visitor);
338 },
340 updateCacheSizeUI: function (smartSizeEnabled)
341 {
342 document.getElementById("useCacheBefore").disabled = smartSizeEnabled;
343 document.getElementById("cacheSize").disabled = smartSizeEnabled;
344 document.getElementById("useCacheAfter").disabled = smartSizeEnabled;
345 },
347 readSmartSizeEnabled: function ()
348 {
349 // The smart_size.enabled preference element is inverted="true", so its
350 // value is the opposite of the actual pref value
351 var disabled = document.getElementById("browser.cache.disk.smart_size.enabled").value;
352 this.updateCacheSizeUI(!disabled);
353 },
355 /**
356 * Converts the cache size from units of KB to units of MB and returns that
357 * value.
358 */
359 readCacheSize: function ()
360 {
361 var preference = document.getElementById("browser.cache.disk.capacity");
362 return preference.value / 1024;
363 },
365 /**
366 * Converts the cache size as specified in UI (in MB) to KB and returns that
367 * value.
368 */
369 writeCacheSize: function ()
370 {
371 var cacheSize = document.getElementById("cacheSize");
372 var intValue = parseInt(cacheSize.value, 10);
373 return isNaN(intValue) ? 0 : intValue * 1024;
374 },
376 /**
377 * Clears the cache.
378 */
379 clearCache: function ()
380 {
381 var cache = Components.classes["@mozilla.org/netwerk/cache-storage-service;1"]
382 .getService(Components.interfaces.nsICacheStorageService);
383 try {
384 cache.clear();
385 } catch(ex) {}
386 this.updateActualCacheSize();
387 },
389 /**
390 * Clears the application cache.
391 */
392 clearOfflineAppCache: function ()
393 {
394 Components.utils.import("resource:///modules/offlineAppCache.jsm");
395 OfflineAppCacheHelper.clear();
397 this.updateActualAppCacheSize();
398 this.updateOfflineApps();
399 },
401 readOfflineNotify: function()
402 {
403 var pref = document.getElementById("browser.offline-apps.notify");
404 var button = document.getElementById("offlineNotifyExceptions");
405 button.disabled = !pref.value;
406 return pref.value;
407 },
409 showOfflineExceptions: function()
410 {
411 var bundlePreferences = document.getElementById("bundlePreferences");
412 var params = { blockVisible : false,
413 sessionVisible : false,
414 allowVisible : false,
415 prefilledHost : "",
416 permissionType : "offline-app",
417 manageCapability : Components.interfaces.nsIPermissionManager.DENY_ACTION,
418 windowTitle : bundlePreferences.getString("offlinepermissionstitle"),
419 introText : bundlePreferences.getString("offlinepermissionstext") };
420 openDialog("chrome://browser/content/preferences/permissions.xul",
421 "Browser:Permissions",
422 "modal=yes",
423 params);
424 },
426 // XXX: duplicated in browser.js
427 _getOfflineAppUsage: function (host, groups)
428 {
429 var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
430 getService(Components.interfaces.nsIApplicationCacheService);
431 if (!groups)
432 groups = cacheService.getGroups();
434 var ios = Components.classes["@mozilla.org/network/io-service;1"].
435 getService(Components.interfaces.nsIIOService);
437 var usage = 0;
438 for (var i = 0; i < groups.length; i++) {
439 var uri = ios.newURI(groups[i], null, null);
440 if (uri.asciiHost == host) {
441 var cache = cacheService.getActiveCache(groups[i]);
442 usage += cache.usage;
443 }
444 }
446 return usage;
447 },
449 /**
450 * Updates the list of offline applications
451 */
452 updateOfflineApps: function ()
453 {
454 var pm = Components.classes["@mozilla.org/permissionmanager;1"]
455 .getService(Components.interfaces.nsIPermissionManager);
457 var list = document.getElementById("offlineAppsList");
458 while (list.firstChild) {
459 list.removeChild(list.firstChild);
460 }
462 var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
463 getService(Components.interfaces.nsIApplicationCacheService);
464 var groups = cacheService.getGroups();
466 var bundle = document.getElementById("bundlePreferences");
468 var enumerator = pm.enumerator;
469 while (enumerator.hasMoreElements()) {
470 var perm = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission);
471 if (perm.type == "offline-app" &&
472 perm.capability != Components.interfaces.nsIPermissionManager.DEFAULT_ACTION &&
473 perm.capability != Components.interfaces.nsIPermissionManager.DENY_ACTION) {
474 var row = document.createElement("listitem");
475 row.id = "";
476 row.className = "offlineapp";
477 row.setAttribute("host", perm.host);
478 var converted = DownloadUtils.
479 convertByteUnits(this._getOfflineAppUsage(perm.host, groups));
480 row.setAttribute("usage",
481 bundle.getFormattedString("offlineAppUsage",
482 converted));
483 list.appendChild(row);
484 }
485 }
486 },
488 offlineAppSelected: function()
489 {
490 var removeButton = document.getElementById("offlineAppsListRemove");
491 var list = document.getElementById("offlineAppsList");
492 if (list.selectedItem) {
493 removeButton.setAttribute("disabled", "false");
494 } else {
495 removeButton.setAttribute("disabled", "true");
496 }
497 },
499 removeOfflineApp: function()
500 {
501 var list = document.getElementById("offlineAppsList");
502 var item = list.selectedItem;
503 var host = item.getAttribute("host");
505 var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
506 .getService(Components.interfaces.nsIPromptService);
507 var flags = prompts.BUTTON_TITLE_IS_STRING * prompts.BUTTON_POS_0 +
508 prompts.BUTTON_TITLE_CANCEL * prompts.BUTTON_POS_1;
510 var bundle = document.getElementById("bundlePreferences");
511 var title = bundle.getString("offlineAppRemoveTitle");
512 var prompt = bundle.getFormattedString("offlineAppRemovePrompt", [host]);
513 var confirm = bundle.getString("offlineAppRemoveConfirm");
514 var result = prompts.confirmEx(window, title, prompt, flags, confirm,
515 null, null, null, {});
516 if (result != 0)
517 return;
519 // clear offline cache entries
520 var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
521 getService(Components.interfaces.nsIApplicationCacheService);
522 var ios = Components.classes["@mozilla.org/network/io-service;1"].
523 getService(Components.interfaces.nsIIOService);
524 var groups = cacheService.getGroups();
525 for (var i = 0; i < groups.length; i++) {
526 var uri = ios.newURI(groups[i], null, null);
527 if (uri.asciiHost == host) {
528 var cache = cacheService.getActiveCache(groups[i]);
529 cache.discard();
530 }
531 }
533 // remove the permission
534 var pm = Components.classes["@mozilla.org/permissionmanager;1"]
535 .getService(Components.interfaces.nsIPermissionManager);
536 pm.remove(host, "offline-app",
537 Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
538 pm.remove(host, "offline-app",
539 Components.interfaces.nsIOfflineCacheUpdateService.ALLOW_NO_WARN);
541 list.removeChild(item);
542 gAdvancedPane.offlineAppSelected();
543 this.updateActualAppCacheSize();
544 },
546 // UPDATE TAB
548 /*
549 * Preferences:
550 *
551 * app.update.enabled
552 * - true if updates to the application are enabled, false otherwise
553 * extensions.update.enabled
554 * - true if updates to extensions and themes are enabled, false otherwise
555 * browser.search.update
556 * - true if updates to search engines are enabled, false otherwise
557 * app.update.auto
558 * - true if updates should be automatically downloaded and installed,
559 * possibly with a warning if incompatible extensions are installed (see
560 * app.update.mode); false if the user should be asked what he wants to do
561 * when an update is available
562 * app.update.mode
563 * - an integer:
564 * 0 do not warn if an update will disable extensions or themes
565 * 1 warn if an update will disable extensions or themes
566 * 2 warn if an update will disable extensions or themes *or* if the
567 * update is a major update
568 */
570 #ifdef MOZ_UPDATER
571 /**
572 * Selects the item of the radiogroup, and sets the warnIncompatible checkbox
573 * based on the pref values and locked states.
574 *
575 * UI state matrix for update preference conditions
576 *
577 * UI Components: Preferences
578 * Radiogroup i = app.update.enabled
579 * Warn before disabling extensions checkbox ii = app.update.auto
580 * iii = app.update.mode
581 *
582 * Disabled states:
583 * Element pref value locked disabled
584 * radiogroup i t/f f false
585 * i t/f *t* *true*
586 * ii t/f f false
587 * ii t/f *t* *true*
588 * iii 0/1/2 t/f false
589 * warnIncompatible i t f false
590 * i t *t* *true*
591 * i *f* t/f *true*
592 * ii t f false
593 * ii t *t* *true*
594 * ii *f* t/f *true*
595 * iii 0/1/2 f false
596 * iii 0/1/2 *t* *true*
597 */
598 updateReadPrefs: function ()
599 {
600 var enabledPref = document.getElementById("app.update.enabled");
601 var autoPref = document.getElementById("app.update.auto");
602 #ifdef XP_WIN
603 #ifdef MOZ_METRO
604 var metroEnabledPref = document.getElementById("app.update.metro.enabled");
605 #endif
606 #endif
607 var radiogroup = document.getElementById("updateRadioGroup");
609 if (!enabledPref.value) // Don't care for autoPref.value in this case.
610 radiogroup.value="manual"; // 3. Never check for updates.
611 #ifdef XP_WIN
612 #ifdef MOZ_METRO
613 // enabledPref.value && autoPref.value && metroEnabledPref.value
614 else if (metroEnabledPref.value && this._showingWin8Prefs)
615 radiogroup.value="autoMetro"; // 0. Automatically install updates
616 #endif
617 #endif
618 else if (autoPref.value) // enabledPref.value && autoPref.value
619 radiogroup.value="auto"; // 1. Automatically install updates
620 else // enabledPref.value && !autoPref.value
621 radiogroup.value="checkOnly"; // 2. Check, but let me choose
623 var canCheck = Components.classes["@mozilla.org/updates/update-service;1"].
624 getService(Components.interfaces.nsIApplicationUpdateService).
625 canCheckForUpdates;
626 // canCheck is false if the enabledPref is false and locked,
627 // or the binary platform or OS version is not known.
628 // A locked pref is sufficient to disable the radiogroup.
629 radiogroup.disabled = !canCheck || enabledPref.locked || autoPref.locked;
631 var modePref = document.getElementById("app.update.mode");
632 var warnIncompatible = document.getElementById("warnIncompatible");
633 // the warnIncompatible checkbox value is set by readAddonWarn
634 warnIncompatible.disabled = radiogroup.disabled || modePref.locked ||
635 !enabledPref.value || !autoPref.value;
636 #ifdef XP_WIN
637 #ifdef MOZ_METRO
638 if (this._showingWin8Prefs) {
639 warnIncompatible.disabled |= metroEnabledPref.value;
640 warnIncompatible.checked |= metroEnabledPref.value;
641 }
642 #endif
643 #endif
645 #ifdef MOZ_MAINTENANCE_SERVICE
646 // Check to see if the maintenance service is installed.
647 // If it is don't show the preference at all.
648 var installed;
649 try {
650 var wrk = Components.classes["@mozilla.org/windows-registry-key;1"]
651 .createInstance(Components.interfaces.nsIWindowsRegKey);
652 wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE,
653 "SOFTWARE\\Mozilla\\MaintenanceService",
654 wrk.ACCESS_READ | wrk.WOW64_64);
655 installed = wrk.readIntValue("Installed");
656 wrk.close();
657 } catch(e) {
658 }
659 if (installed != 1) {
660 document.getElementById("useService").hidden = true;
661 }
662 #endif
663 },
665 /**
666 * Sets the pref values based on the selected item of the radiogroup,
667 * and sets the disabled state of the warnIncompatible checkbox accordingly.
668 */
669 updateWritePrefs: function ()
670 {
671 var enabledPref = document.getElementById("app.update.enabled");
672 var autoPref = document.getElementById("app.update.auto");
673 var modePref = document.getElementById("app.update.mode");
674 #ifdef XP_WIN
675 #ifdef MOZ_METRO
676 var metroEnabledPref = document.getElementById("app.update.metro.enabled");
677 // Initialize the pref to false only if we're showing the option
678 if (this._showingWin8Prefs) {
679 metroEnabledPref.value = false;
680 }
681 #endif
682 #endif
683 var radiogroup = document.getElementById("updateRadioGroup");
684 switch (radiogroup.value) {
685 case "auto": // 1. Automatically install updates for Desktop only
686 enabledPref.value = true;
687 autoPref.value = true;
688 break;
689 #ifdef XP_WIN
690 #ifdef MOZ_METRO
691 case "autoMetro": // 0. Automatically install updates for both Metro and Desktop
692 enabledPref.value = true;
693 autoPref.value = true;
694 metroEnabledPref.value = true;
695 modePref.value = 1;
696 break;
697 #endif
698 #endif
699 case "checkOnly": // 2. Check, but let me choose
700 enabledPref.value = true;
701 autoPref.value = false;
702 break;
703 case "manual": // 3. Never check for updates.
704 enabledPref.value = false;
705 autoPref.value = false;
706 }
708 var warnIncompatible = document.getElementById("warnIncompatible");
709 warnIncompatible.disabled = enabledPref.locked || !enabledPref.value ||
710 autoPref.locked || !autoPref.value ||
711 modePref.locked;
712 #ifdef XP_WIN
713 #ifdef MOZ_METRO
714 if (this._showingWin8Prefs) {
715 warnIncompatible.disabled |= metroEnabledPref.value;
716 warnIncompatible.checked |= metroEnabledPref.value;
717 }
718 #endif
719 #endif
720 },
722 /**
723 * Stores the value of the app.update.mode preference, which is a tristate
724 * integer preference. We store the value here so that we can properly
725 * restore the preference value if the UI reflecting the preference value
726 * is in a state which can represent either of two integer values (as
727 * opposed to only one possible value in the other UI state).
728 */
729 _modePreference: -1,
731 /**
732 * Reads the app.update.mode preference and converts its value into a
733 * true/false value for use in determining whether the "Warn me if this will
734 * disable extensions or themes" checkbox is checked. We also save the value
735 * of the preference so that the preference value can be properly restored if
736 * the user's preferences cannot adequately be expressed by a single checkbox.
737 *
738 * app.update.mode Checkbox State Meaning
739 * 0 Unchecked Do not warn
740 * 1 Checked Warn if there are incompatibilities
741 * 2 Checked Warn if there are incompatibilities,
742 * or the update is major.
743 */
744 readAddonWarn: function ()
745 {
746 var preference = document.getElementById("app.update.mode");
747 var warn = preference.value != 0;
748 gAdvancedPane._modePreference = warn ? preference.value : 1;
749 return warn;
750 },
752 /**
753 * Converts the state of the "Warn me if this will disable extensions or
754 * themes" checkbox into the integer preference which represents it,
755 * returning that value.
756 */
757 writeAddonWarn: function ()
758 {
759 var warnIncompatible = document.getElementById("warnIncompatible");
760 return !warnIncompatible.checked ? 0 : gAdvancedPane._modePreference;
761 },
763 /**
764 * Displays the history of installed updates.
765 */
766 showUpdates: function ()
767 {
768 var prompter = Components.classes["@mozilla.org/updates/update-prompt;1"]
769 .createInstance(Components.interfaces.nsIUpdatePrompt);
770 prompter.showUpdateHistory(window);
771 },
772 #endif
774 // ENCRYPTION TAB
776 /*
777 * Preferences:
778 *
779 * security.default_personal_cert
780 * - a string:
781 * "Select Automatically" select a certificate automatically when a site
782 * requests one
783 * "Ask Every Time" present a dialog to the user so he can select
784 * the certificate to use on a site which
785 * requests one
786 */
788 /**
789 * Displays the user's certificates and associated options.
790 */
791 showCertificates: function ()
792 {
793 openDialog("chrome://pippki/content/certManager.xul",
794 "mozilla:certmanager",
795 "modal=yes", null);
796 },
798 /**
799 * Displays a dialog in which OCSP preferences can be configured.
800 */
801 showOCSP: function ()
802 {
803 openDialog("chrome://mozapps/content/preferences/ocsp.xul",
804 "mozilla:crlmanager",
805 "modal=yes", null);
806 },
808 /**
809 * Displays a dialog from which the user can manage his security devices.
810 */
811 showSecurityDevices: function ()
812 {
813 openDialog("chrome://pippki/content/device_manager.xul",
814 "mozilla:devicemanager",
815 "modal=yes", null);
816 }
817 #ifdef HAVE_SHELL_SERVICE
818 ,
820 // SYSTEM DEFAULTS
822 /*
823 * Preferences:
824 *
825 * browser.shell.checkDefault
826 * - true if a default-browser check (and prompt to make it so if necessary)
827 * occurs at startup, false otherwise
828 */
830 /**
831 * Show button for setting browser as default browser or information that
832 * browser is already the default browser.
833 */
834 updateSetDefaultBrowser: function()
835 {
836 let shellSvc = getShellService();
837 let setDefaultPane = document.getElementById("setDefaultPane");
838 if (!shellSvc) {
839 setDefaultPane.hidden = true;
840 document.getElementById("alwaysCheckDefault").disabled = true;
841 return;
842 }
843 let selectedIndex =
844 shellSvc.isDefaultBrowser(false, true) ? 1 : 0;
845 setDefaultPane.selectedIndex = selectedIndex;
846 },
848 /**
849 * Set browser as the operating system default browser.
850 */
851 setDefaultBrowser: function()
852 {
853 let shellSvc = getShellService();
854 if (!shellSvc)
855 return;
856 shellSvc.setDefaultBrowser(true, false);
857 let selectedIndex =
858 shellSvc.isDefaultBrowser(false, true) ? 1 : 0;
859 document.getElementById("setDefaultPane").selectedIndex = selectedIndex;
860 }
861 #endif
862 };