feat: add new options to about:preferences using overlays

(cherry picked from commit 2a4f2f9578e66130375dad5e2cdd26f2dbe1afef)
This commit is contained in:
adamp01
2022-07-21 12:51:59 +01:00
committed by Alex Kontos
parent 5537eeb192
commit e0e648b801
11 changed files with 463 additions and 1 deletions

View File

@@ -79,6 +79,7 @@
<link rel="localization" href="security/certificates/deviceManager.ftl"/>
<link rel="localization" href="toolkit/updates/history.ftl"/>
<link rel="localization" href="toolkit/global/profileSelection.ftl"/>
<link rel="localization" href="browser/waterfox.ftl"/>
<link rel="shortcut icon" href="chrome://global/skin/icons/settings.svg"/>

View File

@@ -31,6 +31,8 @@ const WaterfoxGlue = {
// Observe chrome-document-loaded topic to detect window open
Services.obs.addObserver(this, "chrome-document-loaded");
// Observe main-pane-loaded topic to detect about:preferences open
Services.obs.addObserver(this, "main-pane-loaded");
},
async getChromeManifest(manifest) {
@@ -44,6 +46,12 @@ const WaterfoxGlue = {
uri = "resource://waterfox/overlays/chrome.manifest";
privateWindow = true;
break;
case "preferences-general":
uri = "resource://waterfox/overlays/preferences-general.manifest";
break;
case "preferences-privacy":
uri = "resource://waterfox/overlays/preferences-privacy.manifest";
break;
}
let chromeManifest = new ChromeManifest(async () => {
let res = await fetch(uri);
@@ -57,7 +65,6 @@ const WaterfoxGlue = {
text = tArr.join("\n");
}
return text;
// return res.text();
}, this.options);
await chromeManifest.parse();
return chromeManifest;
@@ -93,6 +100,35 @@ const WaterfoxGlue = {
UICustomizations.init(window);
}
break;
case "main-pane-loaded":
// Subject is preferences page content window
if (!subject.initialized) {
// If we are not loading directly on privacy, we need to wait until permissionsGroup
// exists before we attempt to load our overlay. If we are loading directly on privacy
// this exists before overlaying occurs, so we have no issues. Loading overlays on
// #general is fine regardless of which pane we refresh/initially load.
await Overlays.load(
await this.getChromeManifest("preferences-general"),
subject
);
if (subject.document.getElementById("permissionsGroup")) {
await Overlays.load(
await this.getChromeManifest("preferences-privacy"),
subject
);
subject.privacyInitialized = true;
} else {
subject.setTimeout(async () => {
await Overlays.load(
await this.getChromeManifest("preferences-privacy"),
subject
);
subject.privacyInitialized = true;
}, 500);
}
subject.initialized = true;
}
break;
}
},
};

View File

@@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DIRS += [
"preferences",
"privatetab",
"statusbar",
"tabfeatures",

View File

@@ -0,0 +1,145 @@
/* 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/. */
/* eslint-env mozilla/browser-window */
"use strict";
const gMainPaneOverlay = {
init() {
// Initialize prefs
window.Preferences.addAll(this.preferences);
// Delayed initialization for Overlay dependent code
this.delayedInit();
},
get preferences() {
return [
// Tab Toolbar Position
{ id: "browser.tabs.toolbarposition", type: "wstring" },
// Tab Context Menu
{ id: "browser.tabs.duplicateTab", type: "bool" },
{ id: "browser.tabs.copyurl", type: "bool" },
{ id: "browser.tabs.activetab", type: "bool" },
{ id: "browser.tabs.copyallurls", type: "bool" },
{ id: "browser.tabs.unloadTab", type: "bool" },
// Additional Tab Prefs
{ id: "browser.tabs.pinnedIconOnly", type: "bool" },
{ id: "browser.tabs.insertAfterCurrent", type: "bool" },
{ id: "browser.tabs.insertRelatedAfterCurrent", type: "bool" },
// Dark Theme
{ id: "ui.systemUsesDarkTheme", type: "int" },
// Restart Menu Item
{ id: "browser.restart_menu.purgecache", type: "bool" },
{ id: "browser.restart_menu.requireconfirm", type: "bool" },
{ id: "browser.restart_menu.showpanelmenubtn", type: "bool" },
// Status Bar
{ id: "browser.statusbar.enabled", type: "bool" },
{ id: "browser.statusbar.appendStatusText", type: "bool" },
// Bookmarks Toolbar Position
{ id: "browser.bookmarks.toolbarposition", type: "wstring" },
// Geolocation API
{ id: "geo.provider.network.url", type: "wstring" },
// Referer
{ id: "network.http.sendRefererHeader", type: "int" },
// WebRTC P2P
{ id: "media.peerconnection.enabled", type: "bool" },
// Images
{ id: "permissions.default.image", type: "int" },
// Scripts
{ id: "javascript.enabled", type: "bool" },
];
},
delayedInit() {
if (!window.initialized) {
setTimeout(() => {
this.delayedInit();
}, 500);
} else if (!document.initialized) {
// Select the correct radio button based on current pref value
this.showRelevantElements();
this.setDynamicThemeGroupValue();
this.setEventListener("dynamicThemeGroup", "command", event => {
this.updateDynamicThemePref(event.target.value);
});
document.initialized = true;
}
},
showRelevantElements() {
let idsGeneral = [
"dynamicThemeGroup",
"restartGroup",
"statusBarGroup",
"bookmarksBarPositionGroup",
"geolocationGroup",
];
let idsPrivacy = ["webrtc", "refheader"];
let win = Services.wm.getMostRecentWindow("navigator:browser");
let uri = win.gBrowser.currentURI.spec;
if (
(uri == "about:preferences" || uri == "about:preferences#general") &&
document.visibilityState == "visible"
) {
for (let id of idsGeneral) {
let el = document.getElementById(id);
if (el) {
el.removeAttribute("hidden");
}
}
} else if (
uri == "about:preferences#privacy" &&
document.visibilityState == "visible"
) {
for (let id of idsPrivacy) {
let el = document.getElementById(id);
if (el) {
el.removeAttribute("hidden");
}
}
}
},
setEventListener(aId, aEventType, aCallback) {
document
.getElementById(aId)
?.addEventListener(aEventType, aCallback.bind(gMainPaneOverlay));
},
async setDynamicThemeGroupValue() {
let radiogroup = document.getElementById("dynamicThemeRadioGroup");
radiogroup.disabled = true;
radiogroup.value = Services.prefs.getIntPref("ui.systemUsesDarkTheme", -1);
radiogroup.disabled = false;
},
async updateDynamicThemePref(value) {
switch (value) {
case "1":
Services.prefs.setIntPref("ui.systemUsesDarkTheme", 1);
break;
case "0":
Services.prefs.setIntPref("ui.systemUsesDarkTheme", 0);
break;
case "-1":
Services.prefs.clearUserPref("ui.systemUsesDarkTheme");
break;
}
},
};

View File

@@ -0,0 +1,116 @@
<!-- 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/. -->
#filter substitution
<?xml version="1.0"?>
<overlay id="preferences-overlay" xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script>
/* eslint-env mozilla/browser-window */
/* globals gMainPaneOverlay */
Services.scriptloader.loadSubScript("chrome://browser/content/overlays/general.js", this);
gMainPaneOverlay.init();
</script>
<vbox id="mainPrefPane">
<!-- Tab Bar Position preferences -->
<vbox id="tabPositionSettingsContainer" insertafter="browserContainersbox">
<label>
<html:h2 data-l10n-id="tab-position-header" />
</label>
<radiogroup id="tabPositionGroup" preference="browser.tabs.toolbarposition">
<radio id="tabBarTopAbove" value="topabove" data-l10n-id="tab-bar-top-above" />
<radio id="tabBarTopBelow" value="topbelow" data-l10n-id="tab-bar-top-below" />
<radio id="tabBarBottomAbove" value="bottomabove" data-l10n-id="tab-bar-bottom-above" />
<radio id="tabBarBottomBelow" value="bottombelow" data-l10n-id="tab-bar-bottom-below" />
</radiogroup>
</vbox>
<!-- Tab Feature preferences -->
<vbox id="tabContextMenuSettingsContainer" insertafter="tabPositionSettingsContainer">
<label>
<html:h2 data-l10n-id="tab-feature-header" />
</label>
<checkbox id="duplicateTab" preference="browser.tabs.duplicateTab" data-l10n-id="show-duplicate-tab" />
<checkbox id="copyUrl" preference="browser.tabs.copyurl" data-l10n-id="show-copy-url" />
<checkbox id="copyActiveTab" preference="browser.tabs.activetab" data-l10n-id="enable-copy-active-tab" />
<checkbox id="copyAllUrls" preference="browser.tabs.copyallurls" data-l10n-id="show-copy-all-urls" />
<checkbox id="unloadTab" preference="browser.tabs.unloadTab" data-l10n-id="show-unload-tab" />
</vbox>
<!-- Additional Tab preferences -->
<vbox id="tabAdditionalSettingsContainer" insertafter="tabContextMenuSettingsContainer">
<label>
<html:h2 data-l10n-id="tab-additional-header" />
</label>
<checkbox id="pinnedTabIconOnly" preference="browser.tabs.pinnedIconOnly" data-l10n-id="pinned-icon-only" />
<checkbox id="openNewTabAtEnd" preference="browser.tabs.insertAfterCurrent"
data-l10n-id="insert-after-current" />
<checkbox id="openRelatedNewTabAtEnd" preference="browser.tabs.insertRelatedAfterCurrent"
data-l10n-id="insert-related-after-current" />
</vbox>
<!-- Dynamic Theme preferences -->
<groupbox id="dynamicThemeGroup" hidden="true" data-category="paneGeneral" insertafter="languagesGroup">
<label>
<html:h2 data-l10n-id="dynamic-theme-header" />
</label>
<radiogroup id="dynamicThemeRadioGroup">
<radio value="1" data-l10n-id="dynamic-theme-dark" />
<radio value="0" data-l10n-id="dynamic-theme-light" />
<radio value="-1" data-l10n-id="dynamic-theme-auto" />
</radiogroup>
</groupbox>
<!-- Restart Menu Item preferences -->
<groupbox id="restartGroup" hidden="true" data-category="paneGeneral" insertafter="dynamicThemeGroup">
<label>
<html:h2 data-l10n-id="restart-header" />
</label>
<checkbox id="browser.restart_menu.showpanelmenubtn" data-l10n-id="restart-show-button"
preference="browser.restart_menu.showpanelmenubtn" />
<checkbox id="browser.restart_menu.purgecache" data-l10n-id="restart-purge-cache"
preference="browser.restart_menu.purgecache" />
<checkbox id="browser.restart_menu.requireconfirm" data-l10n-id="restart-require-confirmation"
preference="browser.restart_menu.requireconfirm" />
</groupbox>
<!-- Status Bar preferences -->
<groupbox id="statusBarGroup" hidden="true" data-category="paneGeneral" insertafter="restartGroup">
<label>
<html:h2 data-l10n-id="statusbar-header" />
</label>
<vbox id="statusBarContainer">
<checkbox id="showStatusBar" preference="browser.statusbar.enabled" data-l10n-id="statusbar-enabled" />
<checkbox id="showStatusLinks" preference="browser.statusbar.appendStatusText"
data-l10n-id="statusbar-show-links" />
</vbox>
</groupbox>
<!-- Bookmarks Toolbar Position preferences -->
<groupbox id="bookmarksBarPositionGroup" hidden="true" data-category="paneGeneral" insertafter="statusBarGroup">
<label>
<html:h2 data-l10n-id="bookmarks-bar-position-header" />
</label>
<radiogroup id="bookmarksBarPositionRadioGroup" preference="browser.bookmarks.toolbarposition">
<radio value="top" data-l10n-id="bookmarks-position-top" />
<radio value="bottom" data-l10n-id="bookmarks-position-bottom" />
</radiogroup>
</groupbox>
#ifdef XP_LINUX
<!-- Geolocation API preferences -->
<groupbox id="geolocationGroup" hidden="true" data-category="paneGeneral"
insertafter="bookmarksBarPositionGroup">
<label>
<html:h2 data-l10n-id="geolocation-api-header" />
</label>
<label data-l10n-id="geolocation-description" />
<radiogroup id="geolocationRadioGroup" preference="geo.provider.network.url">
<radio value="https://location.services.mozilla.com/v1/geolocate?key=%MOZILLA_API_KEY%"
data-l10n-id="geolocation-api-enabled" />
<radio value=" " data-l10n-id="geolocation-api-disabled" />
</radiogroup>
</groupbox>
#endif
</vbox>
</overlay>

View File

@@ -0,0 +1,62 @@
<?xml version="1.0"?>
<!-- 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/. -->
<overlay id="preferences-overlay" xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script>
/* eslint-env mozilla/browser-window */
/* globals gPrivacyPaneOverlay */
Services.scriptloader.loadSubScript("chrome://browser/content/overlays/privacy.js", this);
gPrivacyPaneOverlay.init();
</script>
<vbox id="mainPrefPane">
<!-- WebRTC peer connection -->
<groupbox id="webrtc" data-category="panePrivacy" hidden="true" insertafter="trackingGroup">
<label>
<html:h2 data-l10n-id="webrtc-header" />
</label>
<hbox align="center">
<checkbox id="enableWebRTCP2P" class="tail-with-learn-more" data-l10n-id="enable-webrtc-p2p"
preference="media.peerconnection.enabled" />
<label class="learnMore" is="text-link" href="https://bugzilla.mozilla.org/show_bug.cgi?id=959893"
data-l10n-id="content-blocking-learn-more" />
</hbox>
</groupbox>
<!-- HTTP Referrer Header-->
<groupbox id="refheader" data-category="panePrivacy" hidden="true" insertafter="webrtc">
<label>
<html:h2 data-l10n-id="ref-header" />
</label>
<hbox align="center">
<label id="historyModeLabel" control="doNotsendSecureXSiteReferrer"
data-l10n-id="history-remember-label" />
<!-- Please don't remove the wrapping hbox/vbox/box for these elements. It's used to properly compute the search tooltip position. -->
<hbox>
<menulist id="doNotsendSecureXSiteReferrer" preference="network.http.sendRefererHeader">
<menupopup>
<menuitem data-l10n-id="send-referrer-header-0" value="0" />
<menuitem data-l10n-id="send-referrer-header-1" value="1" />
<menuitem data-l10n-id="send-referrer-header-2" value="2" />
</menupopup>
</menulist>
</hbox>
</hbox>
</groupbox>
<groupbox id="permissionsGroup">
<hbox id="imagePermissions" data-subcategory="permissions-images" insertafter="addonInstallBox">
<checkbox id="loadImages" class="tail-with-learn-more" data-l10n-id="load-images" flex="1" />
</hbox>
<hbox id="javascriptPermissions" data-subcategory="permissions-scripts" insertafter="imagePermissions">
<checkbox id="enableJavaScript" class="tail-with-learn-more" data-l10n-id="enable-javascript"
preference="javascript.enabled" flex="1" />
</hbox>
</groupbox>
</vbox>
</overlay>

View File

@@ -0,0 +1,82 @@
/* 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/. */
/* eslint-env mozilla/browser-window */
/* globals Preferences setEventListener */
"use strict";
const gPrivacyPaneOverlay = {
init() {
// Ensure load images automatically checkbox value is correct.
this.initLoadImages();
Preferences.get("permissions.default.image").on(
"change",
this.loadImagesReadPref.bind(this)
);
if (!window.privacyInitialized) {
setTimeout(() => {
this.delayedInit();
}, 500);
}
},
delayedInit() {
this.updatePrivacyDefaults();
},
// Update privacy item default values
async updatePrivacyDefaults() {
let webRtc = document.getElementById("enableWebRTCP2P");
webRtc.checked = Preferences.get(webRtc.getAttribute("preference")).value;
let refHeader = document.getElementById("doNotsendSecureXSiteReferrer");
refHeader.value = Preferences.get(
refHeader.getAttribute("preference")
).value;
let imagePermissions = document.getElementById("loadImages");
imagePermissions.checked = !!Preferences.get("permissions.default.image")
.value;
let javascriptPermissions = document.getElementById("enableJavaScript");
javascriptPermissions.checked = Preferences.get(
javascriptPermissions.getAttribute("preference")
).value;
},
/**
* Selects the right item of the Load Images Automatically checkbox.
*/
initLoadImages() {
let liaCheckbox = document.getElementById("loadImages");
// If it doesn't exist yet, try again.
if (!liaCheckbox) {
setTimeout(() => {
this.initLoadImages();
}, 500);
return;
}
// Create event listener for when the user clicks
// on one of the radio buttons
setEventListener("loadImages", "command", this.syncToLoadImagesPref);
this.loadImagesReadPref();
},
loadImagesReadPref() {
let enabledPref = Preferences.get("permissions.default.image");
let liaCheckbox = document.getElementById("loadImages");
if (enabledPref.value) {
liaCheckbox.checked = true;
} else {
liaCheckbox.checked = false;
}
},
syncToLoadImagesPref() {
let value = document.getElementById("loadImages").checked ? 1 : 0;
Services.prefs.setIntPref("permissions.default.image", value);
},
};

View File

@@ -0,0 +1,10 @@
browser.jar:
% content browser %content/browser/ contentaccessible=yes
* content/browser/overlays/preferences-general.xhtml (content/preferences-general.xhtml)
content/browser/overlays/preferences-privacy.xhtml (content/preferences-privacy.xhtml)
content/browser/overlays/general.js (content/general.js)
content/browser/overlays/privacy.js (content/privacy.js)
% resource waterfox %waterfox/ contentaccessible=yes
waterfox/overlays/preferences-general.manifest (preferences-general.manifest)
waterfox/overlays/preferences-privacy.manifest (preferences-privacy.manifest)

View File

@@ -0,0 +1,7 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
JAR_MANIFESTS += ["jar.mn"]

View File

@@ -0,0 +1 @@
overlay about:preferences chrome://browser/content/overlays/preferences-general.xhtml

View File

@@ -0,0 +1 @@
overlay about:preferences chrome://browser/content/overlays/preferences-privacy.xhtml