-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
main.js
4290 lines (3805 loc) · 140 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/* import-globals-from extensionControlled.js */
/* import-globals-from preferences.js */
/* import-globals-from /toolkit/mozapps/preferences/fontbuilder.js */
/* import-globals-from /browser/base/content/aboutDialog-appUpdater.js */
/* global MozXULElement */
ChromeUtils.defineESModuleGetters(this, {
BackgroundUpdate: "resource://gre/modules/BackgroundUpdate.sys.mjs",
UpdateListener: "resource://gre/modules/UpdateListener.sys.mjs",
MigrationUtils: "resource:///modules/MigrationUtils.sys.mjs",
TranslationsParent: "resource://gre/actors/TranslationsParent.sys.mjs",
WindowsLaunchOnLogin: "resource://gre/modules/WindowsLaunchOnLogin.sys.mjs",
NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs",
});
// Constants & Enumeration Values
const TYPE_PDF = "application/pdf";
const PREF_PDFJS_DISABLED = "pdfjs.disabled";
// Pref for when containers is being controlled
const PREF_CONTAINERS_EXTENSION = "privacy.userContext.extension";
// Strings to identify ExtensionSettingsStore overrides
const CONTAINERS_KEY = "privacy.containers";
const PREF_USE_SYSTEM_COLORS = "browser.display.use_system_colors";
const PREF_CONTENT_APPEARANCE =
"layout.css.prefers-color-scheme.content-override";
const FORCED_COLORS_QUERY = matchMedia("(forced-colors)");
const AUTO_UPDATE_CHANGED_TOPIC =
UpdateUtils.PER_INSTALLATION_PREFS["app.update.auto"].observerTopic;
const BACKGROUND_UPDATE_CHANGED_TOPIC =
UpdateUtils.PER_INSTALLATION_PREFS["app.update.background.enabled"]
.observerTopic;
const ICON_URL_APP =
AppConstants.platform == "linux"
? "moz-icon://dummy.exe?size=16"
: "chrome://browser/skin/preferences/application.png";
// For CSS. Can be one of "ask", "save" or "handleInternally". If absent, the icon URL
// was set by us to a custom handler icon and CSS should not try to override it.
const APP_ICON_ATTR_NAME = "appHandlerIcon";
Preferences.addAll([
// Startup
{ id: "browser.startup.page", type: "int" },
{ id: "browser.privatebrowsing.autostart", type: "bool" },
// Downloads
{ id: "browser.download.useDownloadDir", type: "bool", inverted: true },
{ id: "browser.download.always_ask_before_handling_new_types", type: "bool" },
{ id: "browser.download.folderList", type: "int" },
{ id: "browser.download.dir", type: "file" },
/* Tab preferences
Preferences:
browser.link.open_newwindow
1 opens such links in the most recent window or tab,
2 opens such links in a new window,
3 opens such links in a new tab
browser.tabs.loadInBackground
- true if display should switch to a new tab which has been opened from a
link, false if display shouldn't switch
browser.tabs.warnOnClose
- true if when closing a window with multiple tabs the user is warned and
allowed to cancel the action, false to just close the window
browser.tabs.warnOnOpen
- true if the user should be warned if he attempts to open a lot of tabs at
once (e.g. a large folder of bookmarks), false otherwise
browser.warnOnQuitShortcut
- true if the user should be warned if they quit using the keyboard shortcut
browser.taskbar.previews.enable
- true if tabs are to be shown in the Windows 7 taskbar
*/
{ id: "browser.link.open_newwindow", type: "int" },
{ id: "browser.tabs.loadInBackground", type: "bool", inverted: true },
{ id: "browser.tabs.warnOnClose", type: "bool" },
{ id: "browser.warnOnQuitShortcut", type: "bool" },
{ id: "browser.tabs.warnOnOpen", type: "bool" },
{ id: "browser.ctrlTab.sortByRecentlyUsed", type: "bool" },
{ id: "browser.tabs.hoverPreview.enabled", type: "bool" },
{ id: "browser.tabs.hoverPreview.showThumbnails", type: "bool" },
// CFR
{
id: "browser.newtabpage.activity-stream.asrouter.userprefs.cfr.addons",
type: "bool",
},
{
id: "browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features",
type: "bool",
},
// Fonts
{ id: "font.language.group", type: "wstring" },
// Languages
{ id: "intl.regional_prefs.use_os_locales", type: "bool" },
// General tab
/* Accessibility
* accessibility.browsewithcaret
- true enables keyboard navigation and selection within web pages using a
visible caret, false uses normal keyboard navigation with no caret
* accessibility.typeaheadfind
- when set to true, typing outside text areas and input boxes will
automatically start searching for what's typed within the current
document; when set to false, no search action happens */
{ id: "accessibility.browsewithcaret", type: "bool" },
{ id: "accessibility.typeaheadfind", type: "bool" },
{ id: "accessibility.blockautorefresh", type: "bool" },
/* Browsing
* general.autoScroll
- when set to true, clicking the scroll wheel on the mouse activates a
mouse mode where moving the mouse down scrolls the document downward with
speed correlated with the distance of the cursor from the original
position at which the click occurred (and likewise with movement upward);
if false, this behavior is disabled
* general.smoothScroll
- set to true to enable finer page scrolling than line-by-line on page-up,
page-down, and other such page movements */
{ id: "general.autoScroll", type: "bool" },
{ id: "general.smoothScroll", type: "bool" },
{ id: "widget.gtk.overlay-scrollbars.enabled", type: "bool", inverted: true },
{ id: "layout.css.always_underline_links", type: "bool" },
{ id: "layout.spellcheckDefault", type: "int" },
{ id: "accessibility.tabfocus", type: "int" },
{
id: "browser.preferences.defaultPerformanceSettings.enabled",
type: "bool",
},
{ id: "dom.ipc.processCount", type: "int" },
{ id: "dom.ipc.processCount.web", type: "int" },
{ id: "layers.acceleration.disabled", type: "bool", inverted: true },
// Files and Applications
{ id: "pref.downloads.disable_button.edit_actions", type: "bool" },
// DRM content
{ id: "media.eme.enabled", type: "bool" },
// Update
{ id: "browser.preferences.advanced.selectedTabIndex", type: "int" },
{ id: "browser.search.update", type: "bool" },
{ id: "privacy.userContext.enabled", type: "bool" },
{
id: "privacy.userContext.newTabContainerOnLeftClick.enabled",
type: "bool",
},
// Picture-in-Picture
{
id: "media.videocontrols.picture-in-picture.video-toggle.enabled",
type: "bool",
},
// Media
{ id: "media.hardwaremediakeys.enabled", type: "bool" },
]);
if (AppConstants.HAVE_SHELL_SERVICE) {
Preferences.addAll([
{ id: "browser.shell.checkDefaultBrowser", type: "bool" },
{ id: "pref.general.disable_button.default_browser", type: "bool" },
]);
}
if (AppConstants.platform === "win") {
Preferences.addAll([
{ id: "browser.taskbar.previews.enable", type: "bool" },
{ id: "ui.osk.enabled", type: "bool" },
]);
}
if (AppConstants.MOZ_UPDATER) {
Preferences.addAll([
{ id: "app.update.disable_button.showUpdateHistory", type: "bool" },
]);
if (AppConstants.NIGHTLY_BUILD) {
Preferences.addAll([{ id: "app.update.suppressPrompts", type: "bool" }]);
}
}
ChromeUtils.defineLazyGetter(this, "gIsPackagedApp", () => {
return Services.sysinfo.getProperty("isPackagedApp");
});
// A promise that resolves when the list of application handlers is loaded.
// We store this in a global so tests can await it.
var promiseLoadHandlersList;
// Load the preferences string bundle for other locales with fallbacks.
function getBundleForLocales(newLocales) {
let locales = Array.from(
new Set([
...newLocales,
...Services.locale.requestedLocales,
Services.locale.lastFallbackLocale,
])
);
return new Localization(
["browser/preferences/preferences.ftl", "branding/brand.ftl"],
false,
undefined,
locales
);
}
var gNodeToObjectMap = new WeakMap();
var gMainPane = {
// The set of types the app knows how to handle. A hash of HandlerInfoWrapper
// objects, indexed by type.
_handledTypes: {},
// The list of types we can show, sorted by the sort column/direction.
// An array of HandlerInfoWrapper objects. We build this list when we first
// load the data and then rebuild it when users change a pref that affects
// what types we can show or change the sort column/direction.
// Note: this isn't necessarily the list of types we *will* show; if the user
// provides a filter string, we'll only show the subset of types in this list
// that match that string.
_visibleTypes: [],
// browser.startup.page values
STARTUP_PREF_BLANK: 0,
STARTUP_PREF_HOMEPAGE: 1,
STARTUP_PREF_RESTORE_SESSION: 3,
// Convenience & Performance Shortcuts
get _list() {
delete this._list;
return (this._list = document.getElementById("handlersView"));
},
get _filter() {
delete this._filter;
return (this._filter = document.getElementById("filter"));
},
_backoffIndex: 0,
/**
* Initialization of gMainPane.
*/
init() {
function setEventListener(aId, aEventType, aCallback) {
document
.getElementById(aId)
.addEventListener(aEventType, aCallback.bind(gMainPane));
}
if (AppConstants.HAVE_SHELL_SERVICE) {
this.updateSetDefaultBrowser();
let win = Services.wm.getMostRecentWindow("navigator:browser");
// Exponential backoff mechanism will delay the polling times if user doesn't
// trigger SetDefaultBrowser for a long time.
let backoffTimes = [
1000, 1000, 1000, 1000, 2000, 2000, 2000, 5000, 5000, 10000,
];
let pollForDefaultBrowser = () => {
let uri = win.gBrowser.currentURI.spec;
if (
(uri == "about:preferences" ||
uri == "about:preferences#general" ||
uri == "about:settings" ||
uri == "about:settings#general") &&
document.visibilityState == "visible"
) {
this.updateSetDefaultBrowser();
}
// approximately a "requestIdleInterval"
window.setTimeout(() => {
window.requestIdleCallback(pollForDefaultBrowser);
}, backoffTimes[this._backoffIndex + 1 < backoffTimes.length ? this._backoffIndex++ : backoffTimes.length - 1]);
};
window.setTimeout(() => {
window.requestIdleCallback(pollForDefaultBrowser);
}, backoffTimes[this._backoffIndex]);
}
this.initBrowserContainers();
this.buildContentProcessCountMenuList();
this.updateDefaultPerformanceSettingsPref();
let defaultPerformancePref = Preferences.get(
"browser.preferences.defaultPerformanceSettings.enabled"
);
defaultPerformancePref.on("change", () => {
this.updatePerformanceSettingsBox({ duringChangeEvent: true });
});
this.updatePerformanceSettingsBox({ duringChangeEvent: false });
this.displayUseSystemLocale();
this.updateProxySettingsUI();
initializeProxyUI(gMainPane);
if (Services.prefs.getBoolPref("intl.multilingual.enabled")) {
gMainPane.initPrimaryBrowserLanguageUI();
}
// We call `initDefaultZoomValues` to set and unhide the
// default zoom preferences menu, and to establish a
// listener for future menu changes.
gMainPane.initDefaultZoomValues();
gMainPane.initTranslations();
if (
Services.prefs.getBoolPref(
"media.videocontrols.picture-in-picture.enabled"
)
) {
document.getElementById("pictureInPictureBox").hidden = false;
setEventListener(
"pictureInPictureToggleEnabled",
"command",
function (event) {
if (!event.target.checked) {
Services.telemetry.recordEvent(
"pictureinpicture.settings",
"disable",
"settings"
);
}
}
);
}
if (AppConstants.platform == "win") {
// Functionality for "Show tabs in taskbar" on Windows 7 and up.
try {
let ver = parseFloat(Services.sysinfo.getProperty("version"));
let showTabsInTaskbar = document.getElementById("showTabsInTaskbar");
showTabsInTaskbar.hidden = ver < 6.1;
} catch (ex) {}
}
let thumbsCheckbox = document.getElementById("tabPreviewShowThumbnails");
let cardPreviewEnabledPref = Preferences.get(
"browser.tabs.hoverPreview.enabled"
);
let maybeShowThumbsCheckbox = () =>
(thumbsCheckbox.hidden = !cardPreviewEnabledPref.value);
cardPreviewEnabledPref.on("change", maybeShowThumbsCheckbox);
maybeShowThumbsCheckbox();
// The "opening multiple tabs might slow down Firefox" warning provides
// an option for not showing this warning again. When the user disables it,
// we provide checkboxes to re-enable the warning.
if (!TransientPrefs.prefShouldBeVisible("browser.tabs.warnOnOpen")) {
document.getElementById("warnOpenMany").hidden = true;
}
if (AppConstants.platform != "win") {
let quitKeyElement =
window.browsingContext.topChromeWindow.document.getElementById(
"key_quitApplication"
);
if (quitKeyElement) {
let quitKey = ShortcutUtils.prettifyShortcut(quitKeyElement);
document.l10n.setAttributes(
document.getElementById("warnOnQuitKey"),
"confirm-on-quit-with-key",
{ quitKey }
);
} else {
// If the quit key element does not exist, then the quit key has
// been disabled, so just hide the checkbox.
document.getElementById("warnOnQuitKey").hidden = true;
}
}
setEventListener("ctrlTabRecentlyUsedOrder", "command", function () {
Services.prefs.clearUserPref("browser.ctrlTab.migrated");
});
setEventListener("manageBrowserLanguagesButton", "command", function () {
gMainPane.showBrowserLanguagesSubDialog({ search: false });
});
if (AppConstants.MOZ_UPDATER) {
// These elements are only compiled in when the updater is enabled
setEventListener("checkForUpdatesButton", "command", function () {
gAppUpdater.checkForUpdates();
});
setEventListener("downloadAndInstallButton", "command", function () {
gAppUpdater.startDownload();
});
setEventListener("updateButton", "command", function () {
gAppUpdater.buttonRestartAfterDownload();
});
setEventListener("checkForUpdatesButton2", "command", function () {
gAppUpdater.checkForUpdates();
});
setEventListener("checkForUpdatesButton3", "command", function () {
gAppUpdater.checkForUpdates();
});
setEventListener("checkForUpdatesButton4", "command", function () {
gAppUpdater.checkForUpdates();
});
}
// Startup pref
setEventListener(
"browserRestoreSession",
"command",
gMainPane.onBrowserRestoreSessionChange
);
if (AppConstants.platform == "win") {
setEventListener(
"windowsLaunchOnLogin",
"command",
gMainPane.onWindowsLaunchOnLoginChange
);
// We do a check here for startWithLastProfile as we could
// have disabled the pref for the user before they're ever
// exposed to the experiment on a new profile.
// If we're using MSIX, we don't show the checkbox as MSIX
// can't write to the registry.
if (
Cc["@mozilla.org/toolkit/profile-service;1"].getService(
Ci.nsIToolkitProfileService
).startWithLastProfile
) {
NimbusFeatures.windowsLaunchOnLogin.recordExposureEvent({
once: true,
});
if (
Services.prefs.getBoolPref(
"browser.startup.windowsLaunchOnLogin.enabled",
false
)
) {
document.getElementById("windowsLaunchOnLoginBox").hidden = false;
}
}
}
gMainPane.updateBrowserStartupUI =
gMainPane.updateBrowserStartupUI.bind(gMainPane);
Preferences.get("browser.privatebrowsing.autostart").on(
"change",
gMainPane.updateBrowserStartupUI
);
Preferences.get("browser.startup.page").on(
"change",
gMainPane.updateBrowserStartupUI
);
Preferences.get("browser.startup.homepage").on(
"change",
gMainPane.updateBrowserStartupUI
);
gMainPane.updateBrowserStartupUI();
if (AppConstants.HAVE_SHELL_SERVICE) {
setEventListener(
"setDefaultButton",
"command",
gMainPane.setDefaultBrowser
);
}
setEventListener(
"disableContainersExtension",
"command",
makeDisableControllingExtension(PREF_SETTING_TYPE, CONTAINERS_KEY)
);
setEventListener("chooseLanguage", "command", gMainPane.showLanguages);
// TODO (Bug 1817084) Remove this code when we disable the extension
setEventListener(
"fxtranslateButton",
"command",
gMainPane.showTranslationExceptions
);
Preferences.get("font.language.group").on(
"change",
gMainPane._rebuildFonts.bind(gMainPane)
);
setEventListener("advancedFonts", "command", gMainPane.configureFonts);
setEventListener("colors", "command", gMainPane.configureColors);
Preferences.get("layers.acceleration.disabled").on(
"change",
gMainPane.updateHardwareAcceleration.bind(gMainPane)
);
setEventListener(
"connectionSettings",
"command",
gMainPane.showConnections
);
setEventListener(
"browserContainersCheckbox",
"command",
gMainPane.checkBrowserContainers
);
setEventListener(
"browserContainersSettings",
"command",
gMainPane.showContainerSettings
);
setEventListener(
"data-migration",
"command",
gMainPane.onMigrationButtonCommand
);
document
.getElementById("migrationWizardDialog")
.addEventListener("MigrationWizard:Close", function (e) {
e.currentTarget.close();
});
if (Services.policies && !Services.policies.isAllowed("profileImport")) {
document.getElementById("dataMigrationGroup").remove();
}
if (
Services.prefs.getBoolPref("browser.backup.preferences.ui.enabled", false)
) {
let backupGroup = document.getElementById("dataBackupGroup");
backupGroup.hidden = false;
backupGroup.removeAttribute("data-hidden-from-search");
}
// For media control toggle button, we support it on Windows, macOS and
// gtk-based Linux.
if (
AppConstants.platform == "win" ||
AppConstants.platform == "macosx" ||
AppConstants.MOZ_WIDGET_GTK
) {
document.getElementById("mediaControlBox").hidden = false;
}
// Initializes the fonts dropdowns displayed in this pane.
this._rebuildFonts();
// Firefox Translations settings panel
// TODO (Bug 1817084) Remove this code when we disable the extension
const fxtranslationsDisabledPrefName = "extensions.translations.disabled";
if (!Services.prefs.getBoolPref(fxtranslationsDisabledPrefName, true)) {
let fxtranslationRow = document.getElementById("fxtranslationsBox");
fxtranslationRow.hidden = false;
}
let emeUIEnabled = Services.prefs.getBoolPref("browser.eme.ui.enabled");
// Force-disable/hide on WinXP:
if (navigator.platform.toLowerCase().startsWith("win")) {
emeUIEnabled =
emeUIEnabled && parseFloat(Services.sysinfo.get("version")) >= 6;
}
if (!emeUIEnabled) {
// Don't want to rely on .hidden for the toplevel groupbox because
// of the pane hiding/showing code potentially interfering:
document
.getElementById("drmGroup")
.setAttribute("style", "display: none !important");
}
// Initialize the Firefox Updates section.
let version = AppConstants.MOZ_APP_VERSION_DISPLAY;
// Include the build ID if this is an "a#" (nightly) build
if (/a\d+$/.test(version)) {
let buildID = Services.appinfo.appBuildID;
let year = buildID.slice(0, 4);
let month = buildID.slice(4, 6);
let day = buildID.slice(6, 8);
version += ` (${year}-${month}-${day})`;
}
// Append "(32-bit)" or "(64-bit)" build architecture to the version number:
let bundle = Services.strings.createBundle(
"chrome://browser/locale/browser.properties"
);
let archResource = Services.appinfo.is64Bit
? "aboutDialog.architecture.sixtyFourBit"
: "aboutDialog.architecture.thirtyTwoBit";
let arch = bundle.GetStringFromName(archResource);
version += ` (${arch})`;
document.l10n.setAttributes(
document.getElementById("updateAppInfo"),
"update-application-version",
{ version }
);
// Show a release notes link if we have a URL.
let relNotesLink = document.getElementById("releasenotes");
let relNotesPrefType = Services.prefs.getPrefType("app.releaseNotesURL");
if (relNotesPrefType != Services.prefs.PREF_INVALID) {
let relNotesURL = Services.urlFormatter.formatURLPref(
"app.releaseNotesURL"
);
if (relNotesURL != "about:blank") {
relNotesLink.href = relNotesURL;
relNotesLink.hidden = false;
}
}
let defaults = Services.prefs.getDefaultBranch(null);
let distroId = defaults.getCharPref("distribution.id", "");
if (distroId) {
let distroString = distroId;
let distroVersion = defaults.getCharPref("distribution.version", "");
if (distroVersion) {
distroString += " - " + distroVersion;
}
let distroIdField = document.getElementById("distributionId");
distroIdField.value = distroString;
distroIdField.hidden = false;
let distroAbout = defaults.getStringPref("distribution.about", "");
if (distroAbout) {
let distroField = document.getElementById("distribution");
distroField.value = distroAbout;
distroField.hidden = false;
}
}
if (AppConstants.MOZ_UPDATER) {
gAppUpdater = new appUpdater();
setEventListener("showUpdateHistory", "command", gMainPane.showUpdates);
let updateDisabled =
Services.policies && !Services.policies.isAllowed("appUpdate");
if (gIsPackagedApp) {
// When we're running inside an app package, there's no point in
// displaying any update content here, and it would get confusing if we
// did, because our updater is not enabled.
// We can't rely on the hidden attribute for the toplevel elements,
// because of the pane hiding/showing code interfering.
document
.getElementById("updatesCategory")
.setAttribute("style", "display: none !important");
document
.getElementById("updateApp")
.setAttribute("style", "display: none !important");
} else if (
updateDisabled ||
UpdateUtils.appUpdateAutoSettingIsLocked() ||
gApplicationUpdateService.manualUpdateOnly
) {
document.getElementById("updateAllowDescription").hidden = true;
document.getElementById("updateSettingsContainer").hidden = true;
} else {
// Start with no option selected since we are still reading the value
document.getElementById("autoDesktop").removeAttribute("selected");
document.getElementById("manualDesktop").removeAttribute("selected");
// Start reading the correct value from the disk
this.readUpdateAutoPref();
setEventListener("updateRadioGroup", "command", event => {
if (event.target.id == "backgroundUpdate") {
this.writeBackgroundUpdatePref();
} else {
this.writeUpdateAutoPref();
}
});
if (this.isBackgroundUpdateUIAvailable()) {
document.getElementById("backgroundUpdate").hidden = false;
// Start reading the background update pref's value from the disk.
this.readBackgroundUpdatePref();
}
}
if (AppConstants.platform == "win") {
// Check for a launch on login registry key
// This accounts for if a user manually changes it in the registry
// Disabling in Task Manager works outside of just deleting the registry key
// in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run
// but it is not possible to change it back to enabled as the disabled value is just a random
// hexadecimal number
let launchOnLoginCheckbox = document.getElementById(
"windowsLaunchOnLogin"
);
WindowsLaunchOnLogin.getLaunchOnLoginEnabled().then(enabled => {
launchOnLoginCheckbox.checked = enabled;
});
WindowsLaunchOnLogin.getLaunchOnLoginApproved().then(
approvedByWindows => {
launchOnLoginCheckbox.disabled = !approvedByWindows;
document.getElementById("windowsLaunchOnLoginDisabledBox").hidden =
approvedByWindows;
}
);
// On Windows, the Application Update setting is an installation-
// specific preference, not a profile-specific one. Show a warning to
// inform users of this.
let updateContainer = document.getElementById(
"updateSettingsContainer"
);
updateContainer.classList.add("updateSettingCrossUserWarningContainer");
document.getElementById(
"updateSettingCrossUserWarningDesc"
).hidden = false;
}
}
// Initilize Application section.
// Observe preferences that influence what we display so we can rebuild
// the view when they change.
Services.obs.addObserver(this, AUTO_UPDATE_CHANGED_TOPIC);
Services.obs.addObserver(this, BACKGROUND_UPDATE_CHANGED_TOPIC);
setEventListener("filter", "command", gMainPane.filter);
setEventListener("typeColumn", "click", gMainPane.sort);
setEventListener("actionColumn", "click", gMainPane.sort);
setEventListener("chooseFolder", "command", gMainPane.chooseFolder);
Preferences.get("browser.download.folderList").on(
"change",
gMainPane.displayDownloadDirPref.bind(gMainPane)
);
Preferences.get("browser.download.dir").on(
"change",
gMainPane.displayDownloadDirPref.bind(gMainPane)
);
gMainPane.displayDownloadDirPref();
// Listen for window unload so we can remove our preference observers.
window.addEventListener("unload", this);
// Figure out how we should be sorting the list. We persist sort settings
// across sessions, so we can't assume the default sort column/direction.
// XXX should we be using the XUL sort service instead?
if (document.getElementById("actionColumn").hasAttribute("sortDirection")) {
this._sortColumn = document.getElementById("actionColumn");
// The typeColumn element always has a sortDirection attribute,
// either because it was persisted or because the default value
// from the xul file was used. If we are sorting on the other
// column, we should remove it.
document.getElementById("typeColumn").removeAttribute("sortDirection");
} else {
this._sortColumn = document.getElementById("typeColumn");
}
appendSearchKeywords(
"browserContainersSettings",
[
"user-context-personal",
"user-context-work",
"user-context-banking",
"user-context-shopping",
].map(ContextualIdentityService.formatContextLabel)
);
AppearanceChooser.init();
// Notify observers that the UI is now ready
Services.obs.notifyObservers(window, "main-pane-loaded");
Preferences.addSyncFromPrefListener(
document.getElementById("defaultFont"),
element => FontBuilder.readFontSelection(element)
);
if (AppConstants.platform == "macosx") {
// We only expose this control on macOS, so don't try
// to add listeners if it doesn't exist.
Preferences.addSyncFromPrefListener(
document.getElementById("useFullKeyboardNavigation"),
() => this.readUseFullKeyboardNavigation()
);
Preferences.addSyncToPrefListener(
document.getElementById("useFullKeyboardNavigation"),
() => this.writeUseFullKeyboardNavigation()
);
}
Preferences.addSyncFromPrefListener(
document.getElementById("checkSpelling"),
() => this.readCheckSpelling()
);
Preferences.addSyncToPrefListener(
document.getElementById("checkSpelling"),
() => this.writeCheckSpelling()
);
Preferences.addSyncFromPrefListener(
document.getElementById("alwaysAsk"),
() => this.readUseDownloadDir()
);
Preferences.addSyncFromPrefListener(
document.getElementById("linkTargeting"),
() => this.readLinkTarget()
);
Preferences.addSyncToPrefListener(
document.getElementById("linkTargeting"),
() => this.writeLinkTarget()
);
Preferences.addSyncFromPrefListener(
document.getElementById("browserContainersCheckbox"),
() => this.readBrowserContainersCheckbox()
);
this.setInitialized();
},
preInit() {
promiseLoadHandlersList = new Promise((resolve, reject) => {
// Load the data and build the list of handlers for applications pane.
// By doing this after pageshow, we ensure it doesn't delay painting
// of the preferences page.
window.addEventListener(
"pageshow",
async () => {
await this.initialized;
try {
this._initListEventHandlers();
this._loadData();
await this._rebuildVisibleTypes();
await this._rebuildView();
await this._sortListView();
resolve();
} catch (ex) {
reject(ex);
}
},
{ once: true }
);
});
},
handleSubcategory(subcategory) {
if (Services.policies && !Services.policies.isAllowed("profileImport")) {
return false;
}
if (subcategory == "migrate") {
this.showMigrationWizardDialog();
return true;
}
if (subcategory == "migrate-autoclose") {
this.showMigrationWizardDialog({ closeTabWhenDone: true });
}
return false;
},
// CONTAINERS
/*
* preferences:
*
* privacy.userContext.enabled
* - true if containers is enabled
*/
/**
* Enables/disables the Settings button used to configure containers
*/
readBrowserContainersCheckbox() {
const pref = Preferences.get("privacy.userContext.enabled");
const settings = document.getElementById("browserContainersSettings");
settings.disabled = !pref.value;
const containersEnabled = Services.prefs.getBoolPref(
"privacy.userContext.enabled"
);
const containersCheckbox = document.getElementById(
"browserContainersCheckbox"
);
containersCheckbox.checked = containersEnabled;
handleControllingExtension(PREF_SETTING_TYPE, CONTAINERS_KEY).then(
isControlled => {
containersCheckbox.disabled = isControlled;
}
);
},
/**
* Show the Containers UI depending on the privacy.userContext.ui.enabled pref.
*/
initBrowserContainers() {
if (!Services.prefs.getBoolPref("privacy.userContext.ui.enabled")) {
// The browserContainersGroup element has its own internal padding that
// is visible even if the browserContainersbox is visible, so hide the whole
// groupbox if the feature is disabled to prevent a gap in the preferences.
document
.getElementById("browserContainersbox")
.setAttribute("data-hidden-from-search", "true");
return;
}
Services.prefs.addObserver(PREF_CONTAINERS_EXTENSION, this);
document.getElementById("browserContainersbox").hidden = false;
this.readBrowserContainersCheckbox();
},
async onGetStarted() {
if (!AppConstants.MOZ_DEV_EDITION) {
return;
}
const win = Services.wm.getMostRecentWindow("navigator:browser");
if (!win) {
return;
}
const user = await fxAccounts.getSignedInUser();
if (user) {
// We have a user, open Sync preferences in the same tab
win.openTrustedLinkIn("about:preferences#sync", "current");
return;
}
if (!(await FxAccounts.canConnectAccount())) {
return;
}
let url = await FxAccounts.config.promiseConnectAccountURI(
"dev-edition-setup"
);
let accountsTab = win.gBrowser.addWebTab(url);
win.gBrowser.selectedTab = accountsTab;
},
// HOME PAGE
/*
* Preferences:
*
* browser.startup.page
* - what page(s) to show when the user starts the application, as an integer:
*
* 0: a blank page (DEPRECATED - this can be set via browser.startup.homepage)
* 1: the home page (as set by the browser.startup.homepage pref)
* 2: the last page the user visited (DEPRECATED)
* 3: windows and tabs from the last session (a.k.a. session restore)
*
* The deprecated option is not exposed in UI; however, if the user has it
* selected and doesn't change the UI for this preference, the deprecated
* option is preserved.
*/
/**
* Utility function to enable/disable the button specified by aButtonID based
* on the value of the Boolean preference specified by aPreferenceID.
*/
updateButtons(aButtonID, aPreferenceID) {
var button = document.getElementById(aButtonID);
var preference = Preferences.get(aPreferenceID);
button.disabled = !preference.value;
return undefined;
},
/**
* Hide/show the "Show my windows and tabs from last time" option based
* on the value of the browser.privatebrowsing.autostart pref.
*/
updateBrowserStartupUI() {
const pbAutoStartPref = Preferences.get(
"browser.privatebrowsing.autostart"
);
const startupPref = Preferences.get("browser.startup.page");
let newValue;
let checkbox = document.getElementById("browserRestoreSession");
checkbox.disabled = pbAutoStartPref.value || startupPref.locked;
newValue = pbAutoStartPref.value
? false
: startupPref.value === this.STARTUP_PREF_RESTORE_SESSION;
if (checkbox.checked !== newValue) {
checkbox.checked = newValue;
}
},
/**
* Fetch the existing default zoom value, initialise and unhide
* the preferences menu. This method also establishes a listener
* to ensure handleDefaultZoomChange is called on future menu
* changes.
*/
async initDefaultZoomValues() {
let win = window.browsingContext.topChromeWindow;
let selected = await win.ZoomUI.getGlobalValue();
let menulist = document.getElementById("defaultZoom");
new SelectionChangedMenulist(menulist, event => {
let parsedZoom = parseFloat((event.target.value / 100).toFixed(2));
gMainPane.handleDefaultZoomChange(parsedZoom);
});
setEventListener("zoomText", "command", function () {
win.ZoomManager.toggleZoom();
document.getElementById("text-zoom-override-warning").hidden =
!document.getElementById("zoomText").checked;
});