From 3b34335cb31bf6e409d9a7213e59a95491a6c3bb Mon Sep 17 00:00:00 2001 From: Martin Kolman Date: Wed, 12 Jul 2023 13:50:04 +0200 Subject: [PATCH] webui: Add Firefox theme for use on Live media The theme upstream is here: https://github.com/garrett/firefox-theme-frame Its main aim is to shape the Firefox window to the most suitable state on Live images: - has a header bar for window switching - has no tab/status/URL bars - has no browser controls As Firefox needs the profile folder to be writable, we need to copy the profile template to a writable directory & use that as the profile path for Firefox. We also need to make sure profile folders from previous runs (possible on Live) are cleaned up. To simplify things, we also use the same theme on non Live images for now, with the expectation that a tweaked theme will provided later. --- anaconda.spec.in | 9 ++++ pyanaconda/ui/webui/__init__.py | 14 +++++- ui/webui/Makefile.am | 4 +- .../default/chrome/userChrome.css | 30 +++++++++++++ ui/webui/firefox-theme/default/user.js | 44 +++++++++++++++++++ .../firefox-theme/live/chrome/userChrome.css | 30 +++++++++++++ ui/webui/firefox-theme/live/user.js | 44 +++++++++++++++++++ ui/webui/webui-desktop | 23 +++++++++- 8 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 ui/webui/firefox-theme/default/chrome/userChrome.css create mode 100644 ui/webui/firefox-theme/default/user.js create mode 100644 ui/webui/firefox-theme/live/chrome/userChrome.css create mode 100644 ui/webui/firefox-theme/live/user.js diff --git a/anaconda.spec.in b/anaconda.spec.in index b8d5fc6ae5fe..4c509fc9fdd4 100644 --- a/anaconda.spec.in +++ b/anaconda.spec.in @@ -441,6 +441,15 @@ rm -rf \ %{_datadir}/cockpit/anaconda-webui/manifest.json %{_datadir}/metainfo/org.cockpit-project.anaconda-webui.metainfo.xml %{_datadir}/cockpit/anaconda-webui/po.*.js.gz +%dir %{_datadir}/anaconda/firefox-theme +%dir %{_datadir}/anaconda/firefox-theme/default +%dir %{_datadir}/anaconda/firefox-theme/default/chrome +%{_datadir}/anaconda/firefox-theme/default/user.js +%{_datadir}/anaconda/firefox-theme/default/chrome/userChrome.css +%dir %{_datadir}/anaconda/firefox-theme/live +%dir %{_datadir}/anaconda/firefox-theme/live/chrome +%{_datadir}/anaconda/firefox-theme/live/user.js +%{_datadir}/anaconda/firefox-theme/live/chrome/userChrome.css %{_libexecdir}/webui-desktop %files gui diff --git a/pyanaconda/ui/webui/__init__.py b/pyanaconda/ui/webui/__init__.py index 111f0440b4ed..7bde7d11a235 100644 --- a/pyanaconda/ui/webui/__init__.py +++ b/pyanaconda/ui/webui/__init__.py @@ -23,9 +23,14 @@ from pyanaconda.core.util import startProgram from pyanaconda.anaconda_loggers import get_module_logger from pyanaconda.core.threads import thread_manager +from pyanaconda.core.configuration.anaconda import conf + +from pyanaconda.core.path import make_directories log = get_module_logger(__name__) +FIREFOX_THEME_DEFAULT = "default" +FIREFOX_THEME_LIVE = "live" class CockpitUserInterface(ui.UserInterface): """This is the main class for Cockpit user interface.""" @@ -113,8 +118,15 @@ def run(self): # This is read by cockpit-desktop and makes it launch Firefox in kiosk mode # instead of the GTK WebKit based web view it launches by default. + # FIXME: looks like "type" should not be used and _is_live_os is private ? + if conf.system.provides_liveuser: + profile_name = FIREFOX_THEME_LIVE + else: + profile_name = FIREFOX_THEME_DEFAULT + proc = startProgram(["/usr/libexec/webui-desktop", - "/cockpit/@localhost/anaconda-webui/index.html"], + "/cockpit/@localhost/anaconda-webui/index.html", + profile_name], reset_lang=False) log.debug("cockpit web view has been started") with open("/run/anaconda/webui_script.pid", "w") as f: diff --git a/ui/webui/Makefile.am b/ui/webui/Makefile.am index fa96a4217849..df90d6fec380 100644 --- a/ui/webui/Makefile.am +++ b/ui/webui/Makefile.am @@ -56,11 +56,13 @@ rsync: install-data-hook: $(WEBPACK_TEST) mkdir -p $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME) cp -r dist/* $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME) + mkdir -p $(DESTDIR)/usr/share/anaconda + cp -r firefox-theme $(DESTDIR)/usr/share/anaconda/ mkdir -p $(DESTDIR)/usr/share/metainfo/ cp org.cockpit-project.$(PACKAGE_NAME).metainfo.xml $(DESTDIR)/usr/share/metainfo/ cp webui-desktop $(DESTDIR)/usr/libexec/ -EXTRA_DIST = dist src +EXTRA_DIST = dist src firefox-theme # checkout common files from Cockpit repository required to build this project; # this has no API stability guarantee, so check out a stable tag when you start diff --git a/ui/webui/firefox-theme/default/chrome/userChrome.css b/ui/webui/firefox-theme/default/chrome/userChrome.css new file mode 100644 index 000000000000..b3100cc9177a --- /dev/null +++ b/ui/webui/firefox-theme/default/chrome/userChrome.css @@ -0,0 +1,30 @@ +/* Adjust the tab, making it fit the text */ +.tabbrowser-tab { + -moz-window-dragging: drag; + margin: auto !important; + max-width: fit-content !important; +} + +/* Adjust the tab's background to match the titlebar */ +.tab-background { + -moz-window-dragging: drag; + background: transparent !important; + box-shadow: none !important; +} + +/* Hide a lot of things we're not going to use */ +#tab-notification-deck, +#PersonalToolbar, +.tab-close-button, +.titlebar-spacer, +.titlebar-close, +#alltabs-button, +#statuspanel { + display: none; +} + +/* Firefox won't load pages if you outright hide the navbar, so we're tricksy */ +#nav-bar { + position: absolute !important; + top: 100%; +} \ No newline at end of file diff --git a/ui/webui/firefox-theme/default/user.js b/ui/webui/firefox-theme/default/user.js new file mode 100644 index 000000000000..f689113501b9 --- /dev/null +++ b/ui/webui/firefox-theme/default/user.js @@ -0,0 +1,44 @@ +// Let us use userChrome.css +user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true); + +// New windows, not tabs +user_pref("browser.link.open_newwindow", 2); +user_pref("browser.link.open_newwindow.restriction", 1); +user_pref("browser.link.open_newwindow.override.external", 2); + +// Dev stuff (for easier UI adusting with ctrl+shift+alt+i) +user_pref("browser.aboutConfig.showWarning", false); +user_pref("devtools.chrome.enabled", true); +user_pref("devtools.debugger.remote-enabled", true); +user_pref("devtools.inspector.showUserAgentStyles", true); + +// Don't have any startup page +user_pref("browser.startup.page", 0); +user_pref("browser.startup.homepage", "about:blank"); +user_pref("browser.startup.homepage_override.once", {}); + +// Don't use a window manager titlebar; use Firefox's built-in one +user_pref("browser.tabs.inTitlebar", 1); + +// Hide the bookmarks +user_pref("browser.toolbars.bookmarks.visibility", "never"); + +// Don't show anything special in the new tab page' +user_pref("browser.newtabpage.activity-stream.default.sites", ""); +user_pref("browser.newtabpage.activity-stream.showSponsored", false); +user_pref("browser.newtabpage.activity-stream.showSponsoredTopSites", false); + +// Remove UI stuff +user_pref("browser.uiCustomization.state", "{\"placements\":{\"widget-overflow-fixed-list\":[],\"unified-extensions-area\":[],\"nav-bar\":[\"back-button\",\"forward-button\",\"stop-reload-button\",\"urlbar-container\",\"downloads-button\",\"unified-extensions-button\"],\"toolbar-menubar\":[\"menubar-items\"],\"TabsToolbar\":[\"tabbrowser-tabs\",\"alltabs-button\"],\"PersonalToolbar\":[\"personal-bookmarks\"]},\"seen\":[\"save-to-pocket-button\",\"developer-button\"],\"dirtyAreaCache\":[\"nav-bar\",\"TabsToolbar\",\"toolbar-menubar\",\"PersonalToolbar\"],\"currentVersion\":19,\"newElementCount\":3}"); + +// Don't set a placeholder for the tab before the page loads and sets title +user_pref("browser.urlbar.placeholderName", ""); + +// Turn off calling home +user_pref("app.normandy.enabled", false); +user_pref("browser.discovery.enabled", false); +user_pref("datareporting.healthreport.uploadEnabled", false); +user_pref("datareporting.policy.dataSubmissionEnabled", false); +user_pref("toolkit.telemetry.unified", false); +user_pref("trailhead.firstrun.didSeeAboutWelcome", true); + diff --git a/ui/webui/firefox-theme/live/chrome/userChrome.css b/ui/webui/firefox-theme/live/chrome/userChrome.css new file mode 100644 index 000000000000..b3100cc9177a --- /dev/null +++ b/ui/webui/firefox-theme/live/chrome/userChrome.css @@ -0,0 +1,30 @@ +/* Adjust the tab, making it fit the text */ +.tabbrowser-tab { + -moz-window-dragging: drag; + margin: auto !important; + max-width: fit-content !important; +} + +/* Adjust the tab's background to match the titlebar */ +.tab-background { + -moz-window-dragging: drag; + background: transparent !important; + box-shadow: none !important; +} + +/* Hide a lot of things we're not going to use */ +#tab-notification-deck, +#PersonalToolbar, +.tab-close-button, +.titlebar-spacer, +.titlebar-close, +#alltabs-button, +#statuspanel { + display: none; +} + +/* Firefox won't load pages if you outright hide the navbar, so we're tricksy */ +#nav-bar { + position: absolute !important; + top: 100%; +} \ No newline at end of file diff --git a/ui/webui/firefox-theme/live/user.js b/ui/webui/firefox-theme/live/user.js new file mode 100644 index 000000000000..f689113501b9 --- /dev/null +++ b/ui/webui/firefox-theme/live/user.js @@ -0,0 +1,44 @@ +// Let us use userChrome.css +user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true); + +// New windows, not tabs +user_pref("browser.link.open_newwindow", 2); +user_pref("browser.link.open_newwindow.restriction", 1); +user_pref("browser.link.open_newwindow.override.external", 2); + +// Dev stuff (for easier UI adusting with ctrl+shift+alt+i) +user_pref("browser.aboutConfig.showWarning", false); +user_pref("devtools.chrome.enabled", true); +user_pref("devtools.debugger.remote-enabled", true); +user_pref("devtools.inspector.showUserAgentStyles", true); + +// Don't have any startup page +user_pref("browser.startup.page", 0); +user_pref("browser.startup.homepage", "about:blank"); +user_pref("browser.startup.homepage_override.once", {}); + +// Don't use a window manager titlebar; use Firefox's built-in one +user_pref("browser.tabs.inTitlebar", 1); + +// Hide the bookmarks +user_pref("browser.toolbars.bookmarks.visibility", "never"); + +// Don't show anything special in the new tab page' +user_pref("browser.newtabpage.activity-stream.default.sites", ""); +user_pref("browser.newtabpage.activity-stream.showSponsored", false); +user_pref("browser.newtabpage.activity-stream.showSponsoredTopSites", false); + +// Remove UI stuff +user_pref("browser.uiCustomization.state", "{\"placements\":{\"widget-overflow-fixed-list\":[],\"unified-extensions-area\":[],\"nav-bar\":[\"back-button\",\"forward-button\",\"stop-reload-button\",\"urlbar-container\",\"downloads-button\",\"unified-extensions-button\"],\"toolbar-menubar\":[\"menubar-items\"],\"TabsToolbar\":[\"tabbrowser-tabs\",\"alltabs-button\"],\"PersonalToolbar\":[\"personal-bookmarks\"]},\"seen\":[\"save-to-pocket-button\",\"developer-button\"],\"dirtyAreaCache\":[\"nav-bar\",\"TabsToolbar\",\"toolbar-menubar\",\"PersonalToolbar\"],\"currentVersion\":19,\"newElementCount\":3}"); + +// Don't set a placeholder for the tab before the page loads and sets title +user_pref("browser.urlbar.placeholderName", ""); + +// Turn off calling home +user_pref("app.normandy.enabled", false); +user_pref("browser.discovery.enabled", false); +user_pref("datareporting.healthreport.uploadEnabled", false); +user_pref("datareporting.policy.dataSubmissionEnabled", false); +user_pref("toolkit.telemetry.unified", false); +user_pref("trailhead.firstrun.didSeeAboutWelcome", true); + diff --git a/ui/webui/webui-desktop b/ui/webui/webui-desktop index 3df4c8ca462e..498b7fc4f764 100755 --- a/ui/webui/webui-desktop +++ b/ui/webui/webui-desktop @@ -39,7 +39,6 @@ set -eu # exec_prefix= is set because the default /usr/libexec contains "${exec_prefix}" exec_prefix="/usr" libexecdir="/usr/libexec" - if [ -z "${1:-}" ]; then echo "Usage: $0 [ssh host]" >&2 exit 1 @@ -61,7 +60,27 @@ case "$1" in ;; esac -BROWSER="/usr/bin/firefox --kiosk" +# prepare empty firefox profile dir with theme based on the passed profile id +FIREFOX_THEME_DIR="/usr/share/anaconda/firefox-theme" +FIREFOX_PROFILE_PATH="/tmp/anaconda-firefox-profile" +THEME_ID=$2 + +# make sure the profile directory exists and is empty +if [ -d ${FIREFOX_PROFILE_PATH} ] +then + echo "Cleaning up existing Anaconda Firefox profile directory." + rm -rf ${FIREFOX_PROFILE_PATH} +fi +mkdir -p ${FIREFOX_PROFILE_PATH} + +# populate the profile directory with our custom Firefox theme +# - theme id is passed as the second argument of this script +THEME_PATH="${FIREFOX_THEME_DIR}/${THEME_ID}" + +cp -a "${THEME_PATH}/." ${FIREFOX_PROFILE_PATH} + +# FIXME: is this hardcoded resolution necessary ? +BROWSER="/usr/bin/firefox --new-instance --window-size 1024,768 --profile ${FIREFOX_PROFILE_PATH}" # start browser in a temporary home dir, so that it does not interfere with your real one BROWSER_HOME=$(mktemp --directory --tmpdir cockpit.desktop.XXXXXX)