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