From 400598a0b1cc52720d1cf65858b84f75fa4c84b7 Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mr-cheffy@users.noreply.github.com> Date: Mon, 23 Jun 2025 00:07:39 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Removed=20legacy=20stylesheets=20config?= =?UTF-8?q?=20and=20implement=20c++=20mods=20backen=E2=80=A6=20(#9131)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/browser/app/profile/zen-browser.js | 3 - src/browser/themes/shared/zen-icons/icons.css | 22 +--- src/dom/base/Document-cpp.patch | 20 +++ src/layout/base/nsStyleSheetService-h.patch | 13 ++ src/zen/common/ZenUIMigration.mjs | 99 ++++----------- src/zen/compact-mode/zen-compact-mode.css | 17 +-- src/zen/downloads/ZenDownloadAnimation.mjs | 28 ++--- src/zen/glance/ZenGlanceManager.mjs | 4 +- src/zen/kbs/ZenKeyboardShortcuts.mjs | 78 ++++++------ src/zen/media/ZenMediaController.mjs | 4 +- src/zen/mods/ZenMods.mjs | 114 +++++------------- src/zen/mods/ZenStyleSheetCache.cpp | 70 +++++++++++ src/zen/mods/ZenStyleSheetCache.h | 57 +++++++++ src/zen/mods/components.conf | 10 ++ src/zen/mods/moz.build | 28 +++++ src/zen/mods/nsIZenModsBackend.idl | 31 +++++ src/zen/mods/nsZenModsBackend.cpp | 105 ++++++++++++++++ src/zen/mods/nsZenModsBackend.h | 36 ++++++ src/zen/split-view/ZenViewSplitter.mjs | 49 ++++---- src/zen/tabs/ZenPinnedTabManager.mjs | 4 +- src/zen/welcome/ZenWelcome.mjs | 4 +- src/zen/workspaces/ZenWorkspace.mjs | 4 +- src/zen/workspaces/ZenWorkspaceCreation.mjs | 4 +- src/zen/workspaces/ZenWorkspaceIcons.mjs | 4 +- src/zen/workspaces/zen-gradient-generator.css | 2 +- 25 files changed, 528 insertions(+), 282 deletions(-) create mode 100644 src/dom/base/Document-cpp.patch create mode 100644 src/layout/base/nsStyleSheetService-h.patch create mode 100644 src/zen/mods/ZenStyleSheetCache.cpp create mode 100644 src/zen/mods/ZenStyleSheetCache.h create mode 100644 src/zen/mods/components.conf create mode 100644 src/zen/mods/nsIZenModsBackend.idl create mode 100644 src/zen/mods/nsZenModsBackend.cpp create mode 100644 src/zen/mods/nsZenModsBackend.h diff --git a/src/browser/app/profile/zen-browser.js b/src/browser/app/profile/zen-browser.js index 523f1ced6..8f68cdbf6 100644 --- a/src/browser/app/profile/zen-browser.js +++ b/src/browser/app/profile/zen-browser.js @@ -11,9 +11,6 @@ // Dont download the multilingual dictionary pref("intl.multilingual.downloadEnabled", false); -// Theme -pref('toolkit.legacyUserProfileCustomizations.stylesheets', true); - #ifdef XP_WIN #include windows.inc #endif diff --git a/src/browser/themes/shared/zen-icons/icons.css b/src/browser/themes/shared/zen-icons/icons.css index 0c05b77ed..af7cd472b 100644 --- a/src/browser/themes/shared/zen-icons/icons.css +++ b/src/browser/themes/shared/zen-icons/icons.css @@ -16,8 +16,7 @@ border-radius: 100% !important; } -#back-button, -#zen-sidebar-web-panel-back { +#back-button { list-style-image: url('back.svg') !important; } @@ -25,19 +24,16 @@ list-style-image: url('move-tab.svg') !important; } -#forward-button, -#zen-sidebar-web-panel-forward { +#forward-button { list-style-image: url('forward.svg') !important; } -#reload-button, -#zen-sidebar-web-panel-reload { +#reload-button { list-style-image: url('reload.svg') !important; } #stop-button, .close-icon, -#zen-sidebar-web-panel-close, #zen-glance-sidebar-close, .zen-theme-picker-custom-list-item-remove { list-style-image: url('close.svg') !important; @@ -281,8 +277,7 @@ list-style-image: url('bookmark-star-on-tray.svg') !important; } -#home-button, -#zen-sidebar-web-panel-home { +#home-button { list-style-image: url('home.svg') !important; } @@ -600,11 +595,6 @@ > #reload-button[displaystop] + #stop-button > .toolbarbutton-animatable-box - > .toolbarbutton-animatable-image, -#zen-sidebar-web-panel-reload[animate] - > #zen-sidebar-web-panel-reload-button[displaystop] - + #zen-sidebar-web-panel-stop-button - > .toolbarbutton-animatable-box > .toolbarbutton-animatable-image { background-image: url('reload-to-stop.svg') !important; } @@ -612,10 +602,6 @@ #stop-reload-button[animate] > #reload-button > .toolbarbutton-animatable-box - > .toolbarbutton-animatable-image, -#zen-sidebar-web-panel-reload[animate] - > #zen-sidebar-web-panel-reload-button - > .toolbarbutton-animatable-box > .toolbarbutton-animatable-image { background-image: url('stop-to-reload.svg') !important; } diff --git a/src/dom/base/Document-cpp.patch b/src/dom/base/Document-cpp.patch new file mode 100644 index 000000000..04aa8afd8 --- /dev/null +++ b/src/dom/base/Document-cpp.patch @@ -0,0 +1,20 @@ +diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp +index a16bef739fcde0f14ba7e53e0acfa3aa2ee1dd3a..78b9d112a56b3d909e31eb4351ee9f3b06c4ef92 100644 +--- a/dom/base/Document.cpp ++++ b/dom/base/Document.cpp +@@ -3332,6 +3332,15 @@ void Document::FillStyleSetUserAndUASheets() { + + ServoStyleSet& styleSet = EnsureStyleSet(); + for (StyleSheet* sheet : *sheetService->UserStyleSheets()) { ++ // If the url starts with "chrome://" and ends with 'zen-themes.css', then ++ // skip it if the document is in a chrome docshell. ++ // This is to avoid loading the user chrome stylesheet in the content ++ // process, which is not allowed. ++ auto spec = sheet->GetSheetURI()->GetSpecOrDefault(); ++ if (!IsInChromeDocShell() && StringBeginsWith(spec, "file://"_ns) && ++ StringEndsWith(spec, "zen-themes.css"_ns)) { ++ continue; ++ } + styleSet.AppendStyleSheet(*sheet); + } + diff --git a/src/layout/base/nsStyleSheetService-h.patch b/src/layout/base/nsStyleSheetService-h.patch new file mode 100644 index 000000000..904403ad6 --- /dev/null +++ b/src/layout/base/nsStyleSheetService-h.patch @@ -0,0 +1,13 @@ +diff --git a/layout/base/nsStyleSheetService.h b/layout/base/nsStyleSheetService.h +index 8c49b338bf8e6830874ace9a08e8c0713167ee58..53a48129b2b6b2adf15e0fe17da14c3b16577966 100644 +--- a/layout/base/nsStyleSheetService.h ++++ b/layout/base/nsStyleSheetService.h +@@ -50,6 +50,8 @@ class nsStyleSheetService final : public nsIStyleSheetService, + + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; + ++ void UpdateZenModStyles(mozilla::StyleSheet* aSheet, nsIURI* aURI, bool aInsert); ++ + static nsStyleSheetService* GetInstance(); + static nsStyleSheetService* gInstance; + diff --git a/src/zen/common/ZenUIMigration.mjs b/src/zen/common/ZenUIMigration.mjs index b8c613106..13f190b3b 100644 --- a/src/zen/common/ZenUIMigration.mjs +++ b/src/zen/common/ZenUIMigration.mjs @@ -1,23 +1,15 @@ // 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/. -const lazy = {}; -var { AppConstants } = ChromeUtils.importESModule('resource://gre/modules/AppConstants.sys.mjs'); - -ChromeUtils.defineESModuleGetters(lazy, { - BrowserWindowTracker: 'resource:///modules/BrowserWindowTracker.sys.mjs', -}); - -class ZenUIMigration { - PREF_NAME = 'zen.migration.version'; - MIGRATION_VERSION = 5; +class nsZenUIMigration { + PREF_NAME = 'zen.ui.migration.version'; + MIGRATION_VERSION = 1; init(isNewProfile) { - const win = lazy.BrowserWindowTracker.getTopWindow(); if (!isNewProfile) { try { - this._migrate(win); + this._migrate(); } catch (e) { console.error('ZenUIMigration: Error during migration', e); } @@ -33,18 +25,11 @@ class ZenUIMigration { Services.prefs.setIntPref(this.PREF_NAME, value); } - _migrate(win) { - if (this._migrationVersion < 1) { - this._migrateV1(win); - } - if (this._migrationVersion < 2) { - this._migrateV2(win); - } - if (this._migrationVersion < 3) { - this._migrateV3(win); - } - if (this._migrationVersion < 4) { - this._migrateV4(win); + _migrate() { + for (let i = 0; i <= this.MIGRATION_VERSION; i++) { + if (this._migrationVersion < i) { + this[`_migrateV${i}`]?.(); + } } } @@ -52,59 +37,21 @@ class ZenUIMigration { this._migrationVersion = this.MIGRATION_VERSION; } - _migrateV1(win) { - // Introduction of the new URL bar, show a message to the user - const notification = win.gNotificationBox.appendNotification( - 'zen-new-urlbar-notification', - { - label: { 'l10n-id': 'zen-new-urlbar-notification' }, - image: 'chrome://browser/skin/notification-icons/persistent-storage-blocked.svg', - priority: win.gNotificationBox.PRIORITY_WARNING_HIGH, - }, - [ - { - 'l10n-id': 'zen-disable', - accessKey: 'D', - callback: () => { - Services.prefs.setBoolPref('zen.urlbar.replace-newtab', false); - }, - }, - { - link: 'https://docs.zen-browser.app/user-manual/urlbar/', - 'l10n-id': 'zen-learn-more-text', - }, - ] - ); - } - - _migrateV2(win) { - if (Services.prefs.getBoolPref('zen.widget.windows.acrylic', false)) { - Services.prefs.setIntPref('widget.windows.mica.toplevel-backdrop', 2); - Services.prefs.clearUserPref('zen.widget.windows.acrylic'); + _migrateV1() { + // If there's an userChrome.css or userContent.css existing, we set + // 'toolkit.legacyUserProfileCustomizations.stylesheets' back to true + // We do this to avoid existing user stylesheets to be ignored + const profileDir = Services.dirsvc.get('ProfD', Ci.nsIFile); + const userChromeFile = profileDir.clone(); + userChromeFile.append('chrome'); + userChromeFile.append('userChrome.css'); + const userContentFile = profileDir.clone(); + userContentFile.append('chrome'); + userContentFile.append('userContent.css'); + if (userChromeFile.exists() || userContentFile.exists()) { + Services.prefs.setBoolPref('toolkit.legacyUserProfileCustomizations.stylesheets', true); } } - - _migrateV3(win) { - const kArea = win.CustomizableUI.AREA_TABSTRIP; - const widgets = win.CustomizableUI.getWidgetsInArea(kArea); - for (const widget of widgets) { - const widgetId = widget.id; - if (widgetId === 'tabbrowser-tabs') { - continue; - } - win.CustomizableUI.removeWidgetFromArea(widgetId); - } - } - - _migrateV4(win) { - if (AppConstants.platform === 'linux') { - return; - } - Services.prefs.setBoolPref( - 'browser.tabs.unloadOnLowMemory', - Services.prefs.getBoolPref('zen.tab-unloader.enabled', true) - ); - } } -export var gZenUIMigration = new ZenUIMigration(); +export var gZenUIMigration = new nsZenUIMigration(); diff --git a/src/zen/compact-mode/zen-compact-mode.css b/src/zen/compact-mode/zen-compact-mode.css index e4e3107e2..5984d47f8 100644 --- a/src/zen/compact-mode/zen-compact-mode.css +++ b/src/zen/compact-mode/zen-compact-mode.css @@ -185,7 +185,15 @@ #navigator-toolbox:has(.tabbrowser-tab:active), &[zen-renaming-tab='true'] #navigator-toolbox, #navigator-toolbox:has( - *:is([panelopen='true'], [open='true'], #urlbar:focus-within, [breakout-extend='true']):not(#urlbar[zen-floating-urlbar='true']):not(tab):not(.zen-compact-mode-ignore) + *:is( + [panelopen='true'], + [open='true'], + #urlbar:focus-within, + [breakout-extend='true'] + ) + :not(#urlbar[zen-floating-urlbar='true']) + :not(tab) + :not(.zen-compact-mode-ignore) ) { &:not([animate='true']) { --zen-compact-mode-func: linear( @@ -328,8 +336,7 @@ } & #titlebar, - & #zen-appcontent-wrapper, - & #zen-sidebar-web-panel-wrapper:has(#zen-sidebar-web-panel:not([pinned='true'])) { + & #zen-appcontent-wrapper { margin-top: var(--zen-element-separation) !important; } @@ -337,10 +344,6 @@ z-index: 3 !important; } - & #zen-sidebar-web-panel-wrapper:has(#zen-sidebar-web-panel[pinned='true']) { - margin-top: calc(var(--zen-element-separation) * 2) !important; - } - & #zen-appcontent-navbar-wrapper { --zen-compact-toolbar-offset: 5px; position: absolute; diff --git a/src/zen/downloads/ZenDownloadAnimation.mjs b/src/zen/downloads/ZenDownloadAnimation.mjs index be1e83463..4cd5eda10 100644 --- a/src/zen/downloads/ZenDownloadAnimation.mjs +++ b/src/zen/downloads/ZenDownloadAnimation.mjs @@ -13,7 +13,7 @@ }, }); - class ZenDownloadAnimation extends ZenDOMOperatedFeature { + class nsZenDownloadAnimation extends ZenDOMOperatedFeature { async init() { await this.#setupDownloadListeners(); } @@ -26,7 +26,7 @@ }); } catch (error) { console.error( - `[${ZenDownloadAnimation.name}] Failed to set up download animation listeners: ${error}` + `[${nsZenDownloadAnimation.name}] Failed to set up download animation listeners: ${error}` ); } } @@ -41,7 +41,7 @@ if (!gZenUIManager._lastClickPosition) { console.warn( - `[${ZenDownloadAnimation.name}] No recent click position available for animation` + `[${nsZenDownloadAnimation.name}] No recent click position available for animation` ); return; } @@ -61,7 +61,7 @@ } } - class ZenDownloadAnimationElement extends HTMLElement { + class nsZenDownloadAnimationElement extends HTMLElement { #boxAnimationElement = null; #boxAnimationTimeoutId = null; #isBoxAnimationRunning = false; @@ -82,14 +82,14 @@ ); this.shadowRoot.appendChild(link); } catch (error) { - console.error(`[${ZenDownloadAnimationElement.name}] Error loading arc styles: ${error}`); + console.error(`[${nsZenDownloadAnimationElement.name}] Error loading arc styles: ${error}`); } } async initializeAnimation(startPosition) { if (!startPosition) { console.warn( - `[${ZenDownloadAnimationElement.name}] No start position provided, skipping animation` + `[${nsZenDownloadAnimationElement.name}] No start position provided, skipping animation` ); return; } @@ -229,7 +229,7 @@ this.#cleanArcAnimation(arcAnimationElement); } catch (error) { - console.error('[ZenDownloadAnimationElement] Error in animation sequence:', error); + console.error('[nsZenDownloadAnimationElement] Error in animation sequence:', error); this.#cleanArcAnimation(arcAnimationElement); } } @@ -309,7 +309,7 @@ // If animation is already in progress, don't start a new one if (this.#isBoxAnimationRunning) { console.warn( - `[${ZenDownloadAnimationElement.name}] Box animation already running, skipping new request.` + `[${nsZenDownloadAnimationElement.name}] Box animation already running, skipping new request.` ); return; } @@ -326,7 +326,7 @@ const wrapper = document.getElementById('zen-main-app-wrapper'); if (!wrapper) { console.warn( - `[${ZenDownloadAnimationElement.name}] Cannot start box animation, Wrapper element not found` + `[${nsZenDownloadAnimationElement.name}] Cannot start box animation, Wrapper element not found` ); return; } @@ -385,7 +385,7 @@ ); } catch (error) { console.error( - `[${ZenDownloadAnimationElement.name}] Error during box entry animation: ${error}` + `[${nsZenDownloadAnimationElement.name}] Error during box entry animation: ${error}` ); this.#cleanBoxAnimation(); } finally { @@ -436,7 +436,7 @@ ).finished; } catch (error) { console.warn( - `[${ZenDownloadAnimationElement.name}] Error during box exit animation: ${error}` + `[${nsZenDownloadAnimationElement.name}] Error during box exit animation: ${error}` ); } finally { this.#cleanBoxAnimation(); @@ -458,7 +458,7 @@ this.#boxAnimationElement.remove(); } catch (error) { console.error( - `[${ZenDownloadAnimationElement.name}] Error removing box animation element: ${error}`, + `[${nsZenDownloadAnimationElement.name}] Error removing box animation element: ${error}`, error ); } @@ -488,7 +488,7 @@ } } - customElements.define('zen-download-animation', ZenDownloadAnimationElement); + customElements.define('zen-download-animation', nsZenDownloadAnimationElement); - new ZenDownloadAnimation(); + new nsZenDownloadAnimation(); } diff --git a/src/zen/glance/ZenGlanceManager.mjs b/src/zen/glance/ZenGlanceManager.mjs index aac97ddcd..ed01f9c60 100644 --- a/src/zen/glance/ZenGlanceManager.mjs +++ b/src/zen/glance/ZenGlanceManager.mjs @@ -2,7 +2,7 @@ // 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/. { - class ZenGlanceManager extends ZenDOMOperatedFeature { + class nsZenGlanceManager extends ZenDOMOperatedFeature { _animating = false; _lazyPref = {}; @@ -783,7 +783,7 @@ } } - window.gZenGlanceManager = new ZenGlanceManager(); + window.gZenGlanceManager = new nsZenGlanceManager(); function registerWindowActors() { gZenActorsManager.addJSWindowActor('ZenGlance', { diff --git a/src/zen/kbs/ZenKeyboardShortcuts.mjs b/src/zen/kbs/ZenKeyboardShortcuts.mjs index 949e4464d..9bc7145d4 100644 --- a/src/zen/kbs/ZenKeyboardShortcuts.mjs +++ b/src/zen/kbs/ZenKeyboardShortcuts.mjs @@ -138,7 +138,7 @@ const VALID_SHORTCUT_GROUPS = [ 'other', ]; -class KeyShortcutModifiers { +class nsKeyShortcutModifiers { #control = false; #alt = false; #shift = false; @@ -161,10 +161,10 @@ class KeyShortcutModifiers { static parseFromJSON(modifiers) { if (!modifiers) { - return new KeyShortcutModifiers(false, false, false, false, false); + return new nsKeyShortcutModifiers(false, false, false, false, false); } - return new KeyShortcutModifiers( + return new nsKeyShortcutModifiers( modifiers['control'] == true, modifiers['alt'] == true, modifiers['shift'] == true, @@ -175,10 +175,10 @@ class KeyShortcutModifiers { static parseFromXHTMLAttribute(modifiers) { if (!modifiers) { - return new KeyShortcutModifiers(false, false, false, false, false); + return new nsKeyShortcutModifiers(false, false, false, false, false); } - return new KeyShortcutModifiers( + return new nsKeyShortcutModifiers( modifiers.includes('control'), modifiers.includes('alt'), modifiers.includes('shift'), @@ -189,7 +189,7 @@ class KeyShortcutModifiers { // used to avoid any future changes to the object static fromObject({ ctrl = false, alt = false, shift = false, meta = false, accel = false }) { - return new KeyShortcutModifiers(ctrl, alt, shift, meta, accel); + return new nsKeyShortcutModifiers(ctrl, alt, shift, meta, accel); } toUserString() { @@ -290,7 +290,7 @@ class KeyShortcut { #key = ''; #keycode = ''; #group = FIREFOX_SHORTCUTS_GROUP; - #modifiers = new KeyShortcutModifiers(false, false, false, false, false); + #modifiers = new nsKeyShortcutModifiers(false, false, false, false, false); #action = ''; #l10nId = ''; #disabled = false; @@ -357,7 +357,7 @@ class KeyShortcut { json['key'], json['keycode'], json['group'], - KeyShortcutModifiers.parseFromJSON(json['modifiers']), + nsKeyShortcutModifiers.parseFromJSON(json['modifiers']), json['action'], json['l10nId'], json['disabled'], @@ -376,7 +376,7 @@ class KeyShortcut { KeyShortcut.sanitizeL10nId(key.getAttribute('data-l10n-id')), key.getAttribute('id') ), - KeyShortcutModifiers.parseFromXHTMLAttribute(key.getAttribute('modifiers')), + nsKeyShortcutModifiers.parseFromXHTMLAttribute(key.getAttribute('modifiers')), key.getAttribute('command'), key.getAttribute('data-l10n-id'), key.getAttribute('disabled') == 'true', @@ -504,8 +504,8 @@ class KeyShortcut { } setModifiers(modifiers) { - if ((!modifiers) instanceof KeyShortcutModifiers) { - throw new Error('Only KeyShortcutModifiers allowed'); + if ((!modifiers) instanceof nsKeyShortcutModifiers) { + throw new Error('Only nsKeyShortcutModifiers allowed'); } this.#modifiers = modifiers; } @@ -554,7 +554,7 @@ class KeyShortcut { clearKeybind() { this.#key = ''; this.#keycode = ''; - this.#modifiers = new KeyShortcutModifiers(false, false, false, false); + this.#modifiers = new nsKeyShortcutModifiers(false, false, false, false); } setNewBinding(shortcut) { @@ -571,7 +571,7 @@ class KeyShortcut { } } -class ZenKeyboardShortcutsLoader { +class nsZenKeyboardShortcutsLoader { constructor() {} get shortcutsFile() { @@ -623,7 +623,7 @@ class ZenKeyboardShortcutsLoader { 'C', '', ZEN_COMPACT_MODE_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, alt: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }), 'cmd_zenCompactModeToggle', 'zen-compact-mode-shortcut-toggle' ) @@ -634,7 +634,7 @@ class ZenKeyboardShortcutsLoader { 'S', '', ZEN_COMPACT_MODE_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, alt: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }), 'cmd_zenCompactModeShowSidebar', 'zen-compact-mode-shortcut-show-sidebar' ) @@ -645,7 +645,7 @@ class ZenKeyboardShortcutsLoader { 'T', '', ZEN_COMPACT_MODE_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, alt: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }), 'cmd_zenCompactModeShowToolbar', 'zen-compact-mode-shortcut-show-toolbar' ) @@ -659,7 +659,7 @@ class ZenKeyboardShortcutsLoader { '', '', ZEN_WORKSPACE_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({}), + nsKeyShortcutModifiers.fromObject({}), `cmd_zenWorkspaceSwitch${i}`, `zen-workspace-shortcut-switch-${i}` ) @@ -671,7 +671,7 @@ class ZenKeyboardShortcutsLoader { 'E', '', ZEN_WORKSPACE_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, alt: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }), 'cmd_zenWorkspaceForward', 'zen-workspace-shortcut-forward' ) @@ -682,7 +682,7 @@ class ZenKeyboardShortcutsLoader { 'Q', '', ZEN_WORKSPACE_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, alt: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }), 'cmd_zenWorkspaceBackward', 'zen-workspace-shortcut-backward' ) @@ -695,7 +695,7 @@ class ZenKeyboardShortcutsLoader { 'G', '', ZEN_SPLIT_VIEW_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, alt: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }), 'cmd_zenSplitViewGrid', 'zen-split-view-shortcut-grid' ) @@ -706,7 +706,7 @@ class ZenKeyboardShortcutsLoader { 'V', '', ZEN_SPLIT_VIEW_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, alt: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }), 'cmd_zenSplitViewVertical', 'zen-split-view-shortcut-vertical' ) @@ -717,7 +717,7 @@ class ZenKeyboardShortcutsLoader { 'H', '', ZEN_SPLIT_VIEW_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, alt: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }), 'cmd_zenSplitViewHorizontal', 'zen-split-view-shortcut-horizontal' ) @@ -728,7 +728,7 @@ class ZenKeyboardShortcutsLoader { 'U', '', ZEN_SPLIT_VIEW_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, alt: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }), 'cmd_zenSplitViewUnsplit', 'zen-split-view-shortcut-unsplit' ) @@ -763,7 +763,7 @@ class ZenKeyboardShortcutsLoader { } } -class ZenKeyboardShortcutsVersioner { +class nsZenKeyboardShortcutsVersioner { static LATEST_KBS_VERSION = 9; constructor() {} @@ -783,11 +783,11 @@ class ZenKeyboardShortcutsVersioner { } isVersionUpToDate() { - return this.version == ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION; + return this.version == nsZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION; } isVersionOutdated() { - return this.version < ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION; + return this.version < nsZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION; } migrateIfNeeded(data) { @@ -806,10 +806,10 @@ class ZenKeyboardShortcutsVersioner { 'Zen CKS: Migrating shortcuts from version', version, 'to', - ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION + nsZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION ); const newData = this.migrate(data, version); - this.version = ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION; + this.version = nsZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION; return newData; } @@ -819,7 +819,7 @@ class ZenKeyboardShortcutsVersioner { } fillDefaultIfNotPresent(data) { - for (let shortcut of ZenKeyboardShortcutsLoader.zenGetDefaultShortcuts()) { + for (let shortcut of nsZenKeyboardShortcutsLoader.zenGetDefaultShortcuts()) { // If it has an ID and we dont find it in the data, we add it if (shortcut.getID() && !data.find((s) => s.getID() == shortcut.getID())) { data.push(shortcut); @@ -837,7 +837,7 @@ class ZenKeyboardShortcutsVersioner { // Migrate from 0 to 1 // Here, we do a complet reset of the shortcuts, // since nothing seems to work properly. - data = ZenKeyboardShortcutsLoader.zenGetDefaultShortcuts(); + data = nsZenKeyboardShortcutsLoader.zenGetDefaultShortcuts(); } if (version < 2) { // Migrate from 1 to 2 @@ -855,7 +855,7 @@ class ZenKeyboardShortcutsVersioner { '', '', ZEN_OTHER_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({}), + nsKeyShortcutModifiers.fromObject({}), 'cmd_zenPinnedTabReset', 'zen-pinned-tab-shortcut-reset' ) @@ -867,7 +867,7 @@ class ZenKeyboardShortcutsVersioner { // detection for internal keys was not working properly, so every internal // shortcut was being saved as a user-editable shortcut. // This migration will fix this issue. - const defaultShortcuts = ZenKeyboardShortcutsLoader.zenGetDefaultShortcuts(); + const defaultShortcuts = nsZenKeyboardShortcutsLoader.zenGetDefaultShortcuts(); // Get the default shortcut, compare the id and set the internal flag if needed for (let shortcut of data) { for (let defaultShortcut of defaultShortcuts) { @@ -892,7 +892,7 @@ class ZenKeyboardShortcutsVersioner { 'B', '', ZEN_OTHER_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ alt: true }), + nsKeyShortcutModifiers.fromObject({ alt: true }), 'cmd_zenToggleSidebar', 'zen-sidebar-shortcut-toggle' ) @@ -907,7 +907,7 @@ class ZenKeyboardShortcutsVersioner { 'C', '', ZEN_OTHER_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, shift: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, shift: true }), 'cmd_zenCopyCurrentURL', 'zen-text-action-copy-url-shortcut' ) @@ -919,7 +919,7 @@ class ZenKeyboardShortcutsVersioner { const listener = (event) => { event.stopPropagation(); - const devToolsShortcuts = ZenKeyboardShortcutsLoader.zenGetDefaultDevToolsShortcuts(); + const devToolsShortcuts = nsZenKeyboardShortcutsLoader.zenGetDefaultDevToolsShortcuts(); gZenKeyboardShortcutsManager.updatedDefaultDevtoolsShortcuts(devToolsShortcuts); window.removeEventListener('zen-devtools-keyset-added', listener); @@ -939,7 +939,7 @@ class ZenKeyboardShortcutsVersioner { 'C', '', ZEN_OTHER_SHORTCUTS_GROUP, - KeyShortcutModifiers.fromObject({ accel: true, shift: true, alt: true }), + nsKeyShortcutModifiers.fromObject({ accel: true, shift: true, alt: true }), 'cmd_zenCopyCurrentURLMarkdown', 'zen-text-action-copy-url-markdown-shortcut' ) @@ -989,7 +989,7 @@ class ZenKeyboardShortcutsVersioner { } var gZenKeyboardShortcutsManager = { - loader: new ZenKeyboardShortcutsLoader(), + loader: new nsZenKeyboardShortcutsLoader(), _hasToLoadDevtools: false, _inlineCommands: [], @@ -1051,7 +1051,7 @@ var gZenKeyboardShortcutsManager = { }; const loadedShortcuts = await innerLoad(); - this.versioner = new ZenKeyboardShortcutsVersioner(loadedShortcuts); + this.versioner = new nsZenKeyboardShortcutsVersioner(loadedShortcuts); return loadedShortcuts; }, @@ -1160,7 +1160,7 @@ var gZenKeyboardShortcutsManager = { if (key.getGroup() != 'devTools') { continue; } - if (ZenKeyboardShortcutsLoader.IGNORED_DEVTOOLS_SHORTCUTS.includes(key.getID())) { + if (nsZenKeyboardShortcutsLoader.IGNORED_DEVTOOLS_SHORTCUTS.includes(key.getID())) { continue; } const originalKey = browser.document.getElementById(key.getID()); diff --git a/src/zen/media/ZenMediaController.mjs b/src/zen/media/ZenMediaController.mjs index 5065aba2b..9b3c18ee8 100644 --- a/src/zen/media/ZenMediaController.mjs +++ b/src/zen/media/ZenMediaController.mjs @@ -10,7 +10,7 @@ true ); - class ZenMediaController { + class nsZenMediaController { _currentMediaController = null; _currentBrowser = null; _mediaUpdateInterval = null; @@ -684,5 +684,5 @@ } } - window.gZenMediaController = new ZenMediaController(); + window.gZenMediaController = new nsZenMediaController(); } diff --git a/src/zen/mods/ZenMods.mjs b/src/zen/mods/ZenMods.mjs index 02116b3a8..aebaf0a3b 100644 --- a/src/zen/mods/ZenMods.mjs +++ b/src/zen/mods/ZenMods.mjs @@ -3,7 +3,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. { - class ZenMods extends ZenPreloadedFeature { + class nsZenMods extends ZenPreloadedFeature { // private properties start #kZenStylesheetModHeader = '/* Zen Mods - Generated by ZenMods.'; #kZenStylesheetModHeaderBody = `* DO NOT EDIT THIS FILE DIRECTLY! @@ -25,24 +25,13 @@ } // Stylesheet service - #sss = null; + #_modsBackend = null; - get #stylesheetService() { - if (!this.#sss) { - this.#sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService( - Ci.nsIStyleSheetService - ); + get #modsBackend() { + if (!this.#_modsBackend) { + this.#_modsBackend = Cc['@mozilla.org/zen/mods-backend;1'].getService(Ci.nsIZenModsBackend); } - return this.#sss; - } - - #ssu = null; - - get #styleSheetUri() { - if (!this.#ssu) { - this.#ssu = Services.io.newFileURI(new FileUtils.File(this.#styleSheetPath)); - } - return this.#ssu; + return this.#_modsBackend; } get #styleSheetPath() { @@ -50,15 +39,7 @@ } async #handleDisableMods() { - if (Services.prefs.getBoolPref('zen.themes.disable-all', false)) { - console.log('[ZenMods]: Disabling mods module.'); - - await this.#removeStylesheet(); - } else { - console.log('[ZenMods]: Enabling mods module.'); - - await this.#rebuildModsStylesheet(); - } + await this.#rebuildModsStylesheet(); } #getStylesheetURIForMod(mod) { @@ -68,60 +49,31 @@ } async #insertStylesheet() { - if (await IOUtils.exists(this.#styleSheetPath)) { - await this.#stylesheetService.loadAndRegisterSheet( - this.#styleSheetUri, - this.#stylesheetService.AGENT_SHEET - ); - } - - if ( - !this.#stylesheetService.sheetRegistered( - this.#styleSheetUri, - this.#stylesheetService.AGENT_SHEET - ) - ) { - console.error(`[ZenMods]: Failed to register stylesheet at ${this.#styleSheetUri.spec}.`); - } - } - - async #removeStylesheet() { - await this.#stylesheetService.unregisterSheet( - this.#styleSheetUri, - this.#stylesheetService.AGENT_SHEET - ); - const rv = this.#stylesheetService.sheetRegistered( - this.#styleSheetUri, - this.#stylesheetService.AGENT_SHEET - ); - await IOUtils.remove(this.#styleSheetPath, { ignoreAbsent: true }); - - if (rv || (await IOUtils.exists(this.#styleSheetPath))) { - console.error(`[ZenMods]: Failed to unregister stylesheet at ${this.#styleSheetUri.spec}.`); - } + this.#modsBackend.rebuildModsStyles(); } async #rebuildModsStylesheet() { - await this.#removeStylesheet(); + const shouldBeEnabled = !Services.prefs.getBoolPref('zen.themes.disable-all', false); + if (shouldBeEnabled) { + const mods = await this.#getEnabledMods(); - const mods = await this.#getEnabledMods(); + await this.#writeStylesheet(mods); - await this.#writeStylesheet(mods); + const modsWithPreferences = await Promise.all( + mods.map(async (mod) => { + const preferences = await this.getModPreferences(mod); - const modsWithPreferences = await Promise.all( - mods.map(async (mod) => { - const preferences = await this.getModPreferences(mod); + return { + name: mod.name, + enabled: mod.enabled, + preferences, + }; + }) + ); - return { - name: mod.name, - enabled: mod.enabled, - preferences, - }; - }) - ); - - this.#setDefaults(modsWithPreferences); - this.#writeToDom(modsWithPreferences); + this.#setDefaults(modsWithPreferences); + this.#writeToDom(modsWithPreferences); + } await this.#insertStylesheet(); } @@ -336,20 +288,8 @@ const data = await response.text(); - let content = data; - - if (isStyleSheet) { - content = '@-moz-document url-prefix("chrome:") {\n'; - - for (const line of data.split('\n')) { - content += ` ${line}\n`; - } - - content += '}'; - } - // convert the data into a Uint8Array - const buffer = new TextEncoder().encode(content); + const buffer = new TextEncoder().encode(data); await IOUtils.write(path, buffer); return; // to exit the loop @@ -715,7 +655,7 @@ // public properties end } - window.gZenMods = new ZenMods(); + window.gZenMods = new nsZenMods(); gZenActorsManager.addJSWindowActor('ZenModsMarketplace', { parent: { diff --git a/src/zen/mods/ZenStyleSheetCache.cpp b/src/zen/mods/ZenStyleSheetCache.cpp new file mode 100644 index 000000000..fb0bdd310 --- /dev/null +++ b/src/zen/mods/ZenStyleSheetCache.cpp @@ -0,0 +1,70 @@ +/* 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/. */ + +#include "ZenStyleSheetCache.h" +#include "nsAppDirectoryServiceDefs.h" + +#include "nsCOMPtr.h" +#include "nsIFile.h" + +#include "mozilla/css/SheetParsingMode.h" +#include "mozilla/GlobalStyleSheetCache.h" + +namespace zen { + +using namespace mozilla; +NS_IMPL_ISUPPORTS(ZenStyleSheetCache, nsISupports) + +auto ZenStyleSheetCache::InvalidateModsSheet() -> void { + mModsSheet = nullptr; +} + +auto ZenStyleSheetCache::GetModsSheet() -> StyleSheet* { + if (mModsSheet) { + // If the mods stylesheet is already loaded, return it. + return mModsSheet; + } + nsCOMPtr chromeFile; + + NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(chromeFile)); + if (!chromeFile) { + // if we don't have a profile yet, that's OK! + return nullptr; + } + + chromeFile->Append(ZEN_MODS_FILENAME); + LoadSheetFile(chromeFile, css::eUserSheetFeatures); + return mModsSheet; +} + +auto ZenStyleSheetCache::LoadSheetFile(nsIFile* aFile, + css::SheetParsingMode aParsingMode) + -> void { + nsCOMPtr uri; + NS_NewFileURI(getter_AddRefs(uri), aFile); + if (!uri) { + return; + } + + auto loader = new mozilla::css::Loader; + auto result = loader->LoadSheetSync(uri, aParsingMode, + css::Loader::UseSystemPrincipal::Yes); + if (MOZ_UNLIKELY(result.isErr())) { + return; + } + mModsSheet = result.unwrapOr(nullptr); +} + +/* static */ +auto ZenStyleSheetCache::Singleton() -> ZenStyleSheetCache* { + MOZ_ASSERT(NS_IsMainThread()); + if (!gZenModsCache) { + gZenModsCache = new ZenStyleSheetCache; + } + return gZenModsCache; +} + +mozilla::StaticRefPtr ZenStyleSheetCache::gZenModsCache; + +} // namespace: zen \ No newline at end of file diff --git a/src/zen/mods/ZenStyleSheetCache.h b/src/zen/mods/ZenStyleSheetCache.h new file mode 100644 index 000000000..f83d35560 --- /dev/null +++ b/src/zen/mods/ZenStyleSheetCache.h @@ -0,0 +1,57 @@ +/* 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/. */ + +#ifndef mozilla_ZenStyleSheetCache_h__ +#define mozilla_ZenStyleSheetCache_h__ + +#include "mozilla/css/Loader.h" +#include "mozilla/NotNull.h" +#include "mozilla/StaticPtr.h" + +#ifndef ZEN_MODS_FILENAME + #define ZEN_MODS_FILENAME u"zen-themes.css"_ns +#endif + +namespace zen { + +class ZenStyleSheetCache final : public nsISupports { + using StyleSheet = mozilla::StyleSheet; + + public: + NS_DECL_ISUPPORTS + + /** + * @brief Clear up the cache and create a new mods stylesheet. + * This is called when we need to recalculate the mods stylesheets. + * @returns The mods stylesheet. + */ + auto InvalidateModsSheet() -> void; + + /** + * @brief Get the mods stylesheet. + * This is called when we need to get the mods stylesheets. + * @returns The mods stylesheet. + */ + auto GetModsSheet() -> StyleSheet*; + + static auto Singleton() -> ZenStyleSheetCache*; + private: + ZenStyleSheetCache() = default; + ~ZenStyleSheetCache() = default; + + /** + * @brief Load the stylesheet from the given file. + * @param aFile The file to load the stylesheet from. + */ + auto LoadSheetFile(nsIFile* aFile, mozilla::css::SheetParsingMode aParsingMode) + -> void; + + static mozilla::StaticRefPtr gZenModsCache; + + RefPtr mModsSheet; +}; + +} // namespace zen + +#endif diff --git a/src/zen/mods/components.conf b/src/zen/mods/components.conf new file mode 100644 index 000000000..d3ec45a0c --- /dev/null +++ b/src/zen/mods/components.conf @@ -0,0 +1,10 @@ +Classes = [ + { + 'cid': '{a0ee4792-b186-4497-936d-53a8989fe836}', + 'interfaces': ['nsIZenModsBackend'], + 'contract_ids': ['@mozilla.org/zen/mods-backend;1'], + 'type': 'zen::nsZenModsBackend', + 'headers': ['mozilla/nsZenModsBackend.h'], + 'processes': ProcessSelector.MAIN_PROCESS_ONLY, + }, +] diff --git a/src/zen/mods/moz.build b/src/zen/mods/moz.build index 3b066b5f4..94794122a 100644 --- a/src/zen/mods/moz.build +++ b/src/zen/mods/moz.build @@ -7,3 +7,31 @@ FINAL_TARGET_FILES.actors += [ "actors/ZenModsMarketplaceChild.sys.mjs", "actors/ZenModsMarketplaceParent.sys.mjs", ] + +XPIDL_SOURCES += [ + "nsIZenModsBackend.idl", +] + +EXPORTS.mozilla += [ + "nsZenModsBackend.h", + "ZenStyleSheetCache.h", +] + +SOURCES += [ + "nsZenModsBackend.cpp", + "ZenStyleSheetCache.cpp", +] + +XPCOM_MANIFESTS += [ + "components.conf", +] + +include("/ipc/chromium/chromium-config.mozbuild") + +LOCAL_INCLUDES += [ + "/dom/base", + "/dom/ipc", +] + +FINAL_LIBRARY = "xul" +XPIDL_MODULE = "zen_mods" diff --git a/src/zen/mods/nsIZenModsBackend.idl b/src/zen/mods/nsIZenModsBackend.idl new file mode 100644 index 000000000..aadccc238 --- /dev/null +++ b/src/zen/mods/nsIZenModsBackend.idl @@ -0,0 +1,31 @@ +/* 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/. */ + +#include "nsISupports.idl" +#include "nsIURI.idl" + +%{C++ +#include "mozilla/ServoStyleSet.h" +#include "mozilla/dom/Document.h" +%} + +/** + * @brief Interface for Zen mods backend. + */ +[scriptable, uuid(a0ee4792-b186-4497-936d-53a8989fe836)] +interface nsIZenModsBackend : nsISupports { + /* + * @brief Remove, clear cache and create a new mods stylesheet. + * This is called when we need to recalculate the mods stylesheets. + * @returns The mods stylesheet. + */ + void invalidateModsSheet(); + /** + * @brief Unregister and register the mods stylesheet. + * This is called when we need to recalculate the mods stylesheets. + * @returns void + */ + void rebuildModsStyles(); +}; + diff --git a/src/zen/mods/nsZenModsBackend.cpp b/src/zen/mods/nsZenModsBackend.cpp new file mode 100644 index 000000000..ce0170dbc --- /dev/null +++ b/src/zen/mods/nsZenModsBackend.cpp @@ -0,0 +1,105 @@ +/* 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/. */ + +#include "nsZenModsBackend.h" + +#include "nsIXULRuntime.h" +#include "nsStyleSheetService.h" + +#include "mozilla/PresShell.h" +#include "mozilla/dom/ContentParent.h" + +#include "nsIURI.h" +#include "nsIFile.h" + +#include "ZenStyleSheetCache.h" + +namespace zen { + +namespace { +/// @brief Helper function to get the singleton instance of ZenStyleSheetCache. +/// @return A pointer to the singleton instance of ZenStyleSheetCache. +static auto GetZenStyleSheetCache() -> ZenStyleSheetCache* { + return ZenStyleSheetCache::Singleton(); +} +} + +// Use the macro to inject all of the definitions for nsISupports. +NS_IMPL_ISUPPORTS(nsZenModsBackend, nsIZenModsBackend) + +nsZenModsBackend::nsZenModsBackend() { + mozilla::Unused << CheckEnabled(); +} + +auto nsZenModsBackend::CheckEnabled() -> bool { + // Check if the mods backend is enabled based on the preference. + nsCOMPtr appInfo = + do_GetService("@mozilla.org/xre/app-info;1"); + bool inSafeMode = false; + if (appInfo) { + appInfo->GetInSafeMode(&inSafeMode); + } + mEnabled = !inSafeMode && + !mozilla::Preferences::GetBool("zen.themes.disable-all", false); + return mEnabled; +} + +auto nsZenModsBackend::RebuildModsStyles() -> nsresult { + // Invalidate the mods stylesheet cache. + GetZenStyleSheetCache()->InvalidateModsSheet(); + // Rebuild the mods stylesheets. + auto modsSheet = GetZenStyleSheetCache()->GetModsSheet(); + if (!modsSheet) { + return NS_ERROR_FAILURE; + } + // Get the service from @mozilla.org/content/style-sheet-service;1 + if (auto* sss = nsStyleSheetService::GetInstance()) { + // Register the mods stylesheet. + sss->UpdateZenModStyles(modsSheet, modsSheet->GetSheetURI(), CheckEnabled()); + } + // Notify that the mods stylesheets have been rebuilt. + return NS_OK; +} + +NS_IMETHODIMP +nsZenModsBackend::InvalidateModsSheet() { + if (!mEnabled) { + return NS_ERROR_NOT_AVAILABLE; + } + GetZenStyleSheetCache()->InvalidateModsSheet(); + return NS_OK; +} + +} // namespace: zen + +void nsStyleSheetService::UpdateZenModStyles(mozilla::StyleSheet* aSheet, nsIURI* aURI, bool aInsert) { + auto sheetType = nsStyleSheetService::USER_SHEET; + this->UnregisterSheet(aURI, sheetType); + if (!aSheet || !aInsert) { + return; // Nothing to update. + } + mSheets[sheetType].AppendElement(aSheet); + // Hold on to a copy of the registered PresShells. + for (mozilla::PresShell* presShell : mPresShells.Clone()) { + // Only allow on chrome documents. + auto doc = presShell->GetDocument(); + if (doc && !doc->IsInChromeDocShell()) { + continue; + } + presShell->NotifyStyleSheetServiceSheetAdded(aSheet, sheetType); + } + + if (XRE_IsParentProcess()) { + nsTArray children; + mozilla::dom::ContentParent::GetAll(children); + + if (children.IsEmpty()) { + return; + } + + for (uint32_t i = 0; i < children.Length(); i++) { + mozilla::Unused << children[i]->SendLoadAndRegisterSheet(aURI, sheetType); + } + } +} diff --git a/src/zen/mods/nsZenModsBackend.h b/src/zen/mods/nsZenModsBackend.h new file mode 100644 index 000000000..21ffbf9f4 --- /dev/null +++ b/src/zen/mods/nsZenModsBackend.h @@ -0,0 +1,36 @@ +/* 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/. */ + +#ifndef mozilla_ZenModsBackend_h__ +#define mozilla_ZenModsBackend_h__ + +#include "nsIZenModsBackend.h" +#include "nsIZenCommonUtils.h" + +#include "mozilla/ServoStyleSet.h" +#include "mozilla/dom/Document.h" + +namespace zen { + +class nsZenModsBackend final : public nsIZenModsBackend { + NS_DECL_ISUPPORTS + NS_DECL_NSIZENMODSBACKEND + + public: + explicit nsZenModsBackend(); + + protected: + /** + * @brief Check for the preference and see if the app is on safe mode. + */ + auto CheckEnabled() -> bool; + + private: + ~nsZenModsBackend() = default; + bool mEnabled = false; +}; + +} // namespace zen + +#endif diff --git a/src/zen/split-view/ZenViewSplitter.mjs b/src/zen/split-view/ZenViewSplitter.mjs index 26285cb14..c67d09e8e 100644 --- a/src/zen/split-view/ZenViewSplitter.mjs +++ b/src/zen/split-view/ZenViewSplitter.mjs @@ -2,7 +2,7 @@ // 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/. -class SplitLeafNode { +class nsSplitLeafNode { /** * The percentage of the size of the parent the node takes up, dependent on parent direction this is either * width or height. @@ -14,7 +14,7 @@ class SplitLeafNode { */ positionToRoot; // position relative to root node /** - * @type {SplitNode} + * @type {nsSplitNode} */ parent; constructor(tab, sizeInParent) { @@ -31,7 +31,7 @@ class SplitLeafNode { } } -class SplitNode extends SplitLeafNode { +class nsSplitNode extends nsSplitLeafNode { /** * @type {string} */ @@ -63,7 +63,7 @@ class SplitNode extends SplitLeafNode { } } -class ZenViewSplitter extends ZenDOMOperatedFeature { +class nsZenViewSplitter extends ZenDOMOperatedFeature { currentView = -1; _data = []; _tabBrowserPanel = null; @@ -441,9 +441,9 @@ class ZenViewSplitter extends ZenDOMOperatedFeature { } /** - * Remove a SplitNode from its tree and the view - * @param {SplitNode} toRemove - * @return {SplitNode} that has to be updated + * Remove a nsSplitNode from its tree and the view + * @param {nsSplitNode} toRemove + * @return {nsSplitNode} that has to be updated */ removeNode(toRemove) { this._removeNodeSplitters(toRemove, true); @@ -825,7 +825,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature { nodeSize = node.sizeInParent; } else { nodeSize = 100; - newParent = new SplitNode(splitDirection, node.sizeInParent); + newParent = new nsSplitNode(splitDirection, node.sizeInParent); if (node.parent) { newParent.parent = node.parent; const nodeIndex = node.parent.children.indexOf(node); @@ -1118,7 +1118,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature { addTabToSplit(tab, splitNode, prepend = true) { const reduce = splitNode.children.length / (splitNode.children.length + 1); splitNode.children.forEach((c) => (c.sizeInParent *= reduce)); - splitNode.addChild(new SplitLeafNode(tab, (1 - reduce) * 100), prepend); + splitNode.addChild(new nsSplitLeafNode(tab, (1 - reduce) * 100), prepend); } /** @@ -1184,21 +1184,24 @@ class ZenViewSplitter extends ZenDOMOperatedFeature { calculateLayoutTree(tabs, gridType) { let rootNode; if (gridType === 'vsep' || (tabs.length === 2 && gridType === 'grid')) { - rootNode = new SplitNode('row'); - rootNode.children = tabs.map((tab) => new SplitLeafNode(tab, 100 / tabs.length)); + rootNode = new nsSplitNode('row'); + rootNode.children = tabs.map((tab) => new nsSplitLeafNode(tab, 100 / tabs.length)); } else if (gridType === 'hsep') { - rootNode = new SplitNode('column'); - rootNode.children = tabs.map((tab) => new SplitLeafNode(tab, 100 / tabs.length)); + rootNode = new nsSplitNode('column'); + rootNode.children = tabs.map((tab) => new nsSplitLeafNode(tab, 100 / tabs.length)); } else if (gridType === 'grid') { - rootNode = new SplitNode('row'); + rootNode = new nsSplitNode('row'); const rowWidth = 100 / Math.ceil(tabs.length / 2); for (let i = 0; i < tabs.length - 1; i += 2) { - const columnNode = new SplitNode('column', rowWidth, 100); - columnNode.children = [new SplitLeafNode(tabs[i], 50), new SplitLeafNode(tabs[i + 1], 50)]; + const columnNode = new nsSplitNode('column', rowWidth, 100); + columnNode.children = [ + new nsSplitLeafNode(tabs[i], 50), + new nsSplitLeafNode(tabs[i + 1], 50), + ]; rootNode.addChild(columnNode); } if (tabs.length % 2 !== 0) { - rootNode.addChild(new SplitLeafNode(tabs[tabs.length - 1], rowWidth)); + rootNode.addChild(new nsSplitLeafNode(tabs[tabs.length - 1], rowWidth)); } } @@ -1260,7 +1263,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature { /** * Apply grid layout to tabBrowserPanel * - * @param {SplitNode} splitNode SplitNode + * @param {nsSplitNode} splitNode nsSplitNode */ applyGridLayout(splitNode) { if (!splitNode.positionToRoot) { @@ -1317,7 +1320,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature { /** * * @param {String} orient - * @param {SplitNode} parentNode + * @param {nsSplitNode} parentNode * @param {Number} idx */ createSplitter(orient, parentNode, idx) { @@ -1332,7 +1335,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature { } /** - * @param {SplitNode} parentNode + * @param {nsSplitNode} parentNode * @param {number|undefined} splittersNeeded if provided the amount of splitters for node will be adjusted to match */ getSplitters(parentNode, splittersNeeded) { @@ -1365,7 +1368,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature { /** * @param {Tab} tab - * @return {SplitNode} splitNode + * @return {nsSplitNode} splitNode */ getSplitNodeFromTab(tab) { return this._tabToSplitNode.get(tab); @@ -1703,7 +1706,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature { if (parentNode.direction !== splitDirection) { this.splitIntoNode( droppedOnSplitNode, - new SplitLeafNode(draggedTab, 50), + new nsSplitLeafNode(draggedTab, 50), hoverSide, 0.5 ); @@ -1900,4 +1903,4 @@ class ZenViewSplitter extends ZenDOMOperatedFeature { } } -window.gZenViewSplitter = new ZenViewSplitter(); +window.gZenViewSplitter = new nsZenViewSplitter(); diff --git a/src/zen/tabs/ZenPinnedTabManager.mjs b/src/zen/tabs/ZenPinnedTabManager.mjs index eed02247f..0e46a678f 100644 --- a/src/zen/tabs/ZenPinnedTabManager.mjs +++ b/src/zen/tabs/ZenPinnedTabManager.mjs @@ -51,7 +51,7 @@ } } - class ZenPinnedTabManager extends ZenDOMOperatedFeature { + class nsZenPinnedTabManager extends ZenDOMOperatedFeature { MAX_ESSENTIALS_TABS = 12; async init() { @@ -1104,5 +1104,5 @@ } } - window.gZenPinnedTabManager = new ZenPinnedTabManager(); + window.gZenPinnedTabManager = new nsZenPinnedTabManager(); } diff --git a/src/zen/welcome/ZenWelcome.mjs b/src/zen/welcome/ZenWelcome.mjs index e4e735cc7..295d3c578 100644 --- a/src/zen/welcome/ZenWelcome.mjs +++ b/src/zen/welcome/ZenWelcome.mjs @@ -126,7 +126,7 @@ } } - class ZenWelcomePages { + class nsZenWelcomePages { constructor(pages) { this._currentPage = -1; this._pages = pages; @@ -740,7 +740,7 @@ delay: getMotion().stagger(0.4), } ); - new ZenWelcomePages(getWelcomePages()); + new nsZenWelcomePages(getWelcomePages()); }); await animate( button, diff --git a/src/zen/workspaces/ZenWorkspace.mjs b/src/zen/workspaces/ZenWorkspace.mjs index 6d2fa56db..4795fed0b 100644 --- a/src/zen/workspaces/ZenWorkspace.mjs +++ b/src/zen/workspaces/ZenWorkspace.mjs @@ -2,7 +2,7 @@ // 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/. { - class ZenWorkspace extends MozXULElement { + class nsZenWorkspace extends MozXULElement { static get markup() { return ` @@ -220,5 +220,5 @@ } } - customElements.define('zen-workspace', ZenWorkspace); + customElements.define('zen-workspace', nsZenWorkspace); } diff --git a/src/zen/workspaces/ZenWorkspaceCreation.mjs b/src/zen/workspaces/ZenWorkspaceCreation.mjs index 87fb8c278..927590e98 100644 --- a/src/zen/workspaces/ZenWorkspaceCreation.mjs +++ b/src/zen/workspaces/ZenWorkspaceCreation.mjs @@ -1,5 +1,5 @@ { - class ZenWorkspaceCreation extends MozXULElement { + class nsZenWorkspaceCreation extends MozXULElement { #wasInCollapsedMode = false; promiseInitialized = new Promise((resolve) => { @@ -336,5 +336,5 @@ } } - customElements.define('zen-workspace-creation', ZenWorkspaceCreation); + customElements.define('zen-workspace-creation', nsZenWorkspaceCreation); } diff --git a/src/zen/workspaces/ZenWorkspaceIcons.mjs b/src/zen/workspaces/ZenWorkspaceIcons.mjs index e997bdcd6..b512fbe49 100644 --- a/src/zen/workspaces/ZenWorkspaceIcons.mjs +++ b/src/zen/workspaces/ZenWorkspaceIcons.mjs @@ -2,7 +2,7 @@ // 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/. { - class ZenWorkspaceIcons extends MozXULElement { + class nsZenWorkspaceIcons extends MozXULElement { constructor() { super(); } @@ -181,5 +181,5 @@ } } - customElements.define('zen-workspace-icons', ZenWorkspaceIcons); + customElements.define('zen-workspace-icons', nsZenWorkspaceIcons); } diff --git a/src/zen/workspaces/zen-gradient-generator.css b/src/zen/workspaces/zen-gradient-generator.css index 90c22c287..24564c89d 100644 --- a/src/zen/workspaces/zen-gradient-generator.css +++ b/src/zen/workspaces/zen-gradient-generator.css @@ -124,7 +124,7 @@ #PanelUI-zen-gradient-generator-custom-list { margin-top: 15px; - &:not(:has(.zen-theme-picker-custom-list-item)) { + &:empty { display: none; }