mirror of
				https://github.com/zen-browser/desktop.git
				synced 2025-10-26 12:27:50 +00:00 
			
		
		
		
	fix: Fixed crashes with mods and default lightness will be 50%, b=no-bug, c=mods, workspaces
This commit is contained in:
		| @@ -8,11 +8,9 @@ pref('zen.mods.auto-update-days', 20); // In days | ||||
|  | ||||
| #ifdef MOZILLA_OFFICIAL | ||||
|   pref('zen.mods.auto-update', true); | ||||
|   pref('zen.rice.api.url', 'https://share.zen-browser.app', locked); | ||||
|   pref('zen.injections.match-urls', 'https://zen-browser.app/*,https://share.zen-browser.app/*', locked); | ||||
|   pref('zen.injections.match-urls', 'https://zen-browser.app/*', locked); | ||||
| #else | ||||
|   pref('zen.mods.auto-update', false); | ||||
|   pref('zen.rice.api.url', "http://localhost", locked); | ||||
|   pref('zen.injections.match-urls', 'http://localhost/*', locked); | ||||
| #endif | ||||
|  | ||||
|   | ||||
| @@ -1,20 +1,24 @@ | ||||
| diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp | ||||
| index a16bef739fcde0f14ba7e53e0acfa3aa2ee1dd3a..f928c0f1df4e86bd344ab7e57dab112234fb92e8 100644 | ||||
| index a16bef739fcde0f14ba7e53e0acfa3aa2ee1dd3a..7c4bee2422f76272022f0c793aa52ea02e292bde 100644 | ||||
| --- a/dom/base/Document.cpp | ||||
| +++ b/dom/base/Document.cpp | ||||
| @@ -3332,6 +3332,15 @@ void Document::FillStyleSetUserAndUASheets() { | ||||
| @@ -10,6 +10,7 @@ | ||||
|   | ||||
|    ServoStyleSet& styleSet = EnsureStyleSet(); | ||||
|    for (StyleSheet* sheet : *sheetService->UserStyleSheets()) { | ||||
| +    // If the url starts with "file://" and ends with 'zen-themes.css', then | ||||
| +    // skip it if the document is not 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; | ||||
| +    } | ||||
|  #include "mozilla/dom/Document.h" | ||||
|  #include "mozilla/dom/DocumentInlines.h" | ||||
| +#include "mozilla/ZenStyleSheetCache.h" | ||||
|   | ||||
|  #include <inttypes.h> | ||||
|  #include <stdlib.h> | ||||
| @@ -3335,6 +3336,11 @@ void Document::FillStyleSetUserAndUASheets() { | ||||
|      styleSet.AppendStyleSheet(*sheet); | ||||
|    } | ||||
|   | ||||
| +  if (auto sheet = zen::ZenStyleSheetCache::Singleton()->GetModsSheet(); sheet && IsInChromeDocShell()) { | ||||
| +    // The mods sheet is only used in the chrome docshell. | ||||
| +    styleSet.AppendStyleSheet(*sheet); | ||||
| +  } | ||||
| + | ||||
|    StyleSheet* sheet = IsInChromeDocShell() ? cache->GetUserChromeSheet() | ||||
|                                             : cache->GetUserContentSheet(); | ||||
|    if (sheet) { | ||||
|   | ||||
| @@ -1,13 +0,0 @@ | ||||
| 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; | ||||
|   | ||||
| @@ -48,9 +48,18 @@ | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     async #readStylesheet() { | ||||
|       const path = this.modsRootPath; | ||||
|       if (!(await IOUtils.exists(path))) { | ||||
|         return ''; | ||||
|       } | ||||
|       return await IOUtils.readUTF8(this.#styleSheetPath); | ||||
|     } | ||||
|  | ||||
|     async #insertStylesheet() { | ||||
|       try { | ||||
|         this.#modsBackend.rebuildModsStyles(); | ||||
|         const content = await this.#readStylesheet(); | ||||
|         this.#modsBackend.rebuildModsStyles(content); | ||||
|       } catch (e) { | ||||
|         console.warn('[ZenMods]: Error rebuilding mods styles:', e); | ||||
|       } | ||||
|   | ||||
| @@ -11,29 +11,36 @@ | ||||
| #include "mozilla/css/SheetParsingMode.h" | ||||
| #include "mozilla/GlobalStyleSheetCache.h" | ||||
|  | ||||
| #define GET_MODS_FILE(chromeFile, err) \ | ||||
|   NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(chromeFile)); \ | ||||
|   if (!chromeFile) { \ | ||||
|     return err; \ | ||||
|   } \ | ||||
|   chromeFile->Append(ZEN_MODS_FILENAME); | ||||
|  | ||||
| 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<nsIFile> chromeFile; | ||||
|   GET_MODS_FILE(chromeFile, nullptr); | ||||
|  | ||||
|   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; | ||||
|   // Create the mods stylesheet if it doesn't exist. | ||||
|   bool exists; | ||||
|   chromeFile->Exists(&exists); | ||||
|   if (!exists) { | ||||
|     nsresult rv = chromeFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644); | ||||
|     if (NS_FAILED(rv)) { | ||||
|       return nullptr; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   chromeFile->Append(ZEN_MODS_FILENAME); | ||||
|   LoadSheetFile(chromeFile, css::eUserSheetFeatures); | ||||
|   return mModsSheet; | ||||
| } | ||||
| @@ -49,7 +56,7 @@ auto ZenStyleSheetCache::LoadSheetFile(nsIFile* aFile, | ||||
|  | ||||
|   auto loader = new mozilla::css::Loader; | ||||
|   auto result = loader->LoadSheetSync(uri, aParsingMode, | ||||
|                                           css::Loader::UseSystemPrincipal::Yes); | ||||
|                                       css::Loader::UseSystemPrincipal::Yes); | ||||
|   if (MOZ_UNLIKELY(result.isErr())) { | ||||
|     return; | ||||
|   } | ||||
| @@ -65,6 +72,20 @@ auto ZenStyleSheetCache::Singleton() -> ZenStyleSheetCache* { | ||||
|   return gZenModsCache; | ||||
| } | ||||
|  | ||||
| nsresult ZenStyleSheetCache::RebuildModsStylesheets(const nsACString& aContents) { | ||||
|   // Re-parse the mods stylesheet. By doing so, we read  | ||||
|   // Once we have the data as a nsACString, we call ReparseSheet from the | ||||
|   // StyleSheet class to re-parse the stylesheet. | ||||
|   auto sheet = GetModsSheet(); | ||||
|   if (!sheet) { | ||||
|     return NS_ERROR_FAILURE; | ||||
|   } | ||||
|   ErrorResult aRv; | ||||
|   sheet->ReparseSheet(aContents, aRv); | ||||
|   return aRv.StealNSResult(); | ||||
| } | ||||
|  | ||||
|  | ||||
| mozilla::StaticRefPtr<ZenStyleSheetCache> ZenStyleSheetCache::gZenModsCache;  | ||||
|  | ||||
| } // namespace: zen | ||||
| @@ -21,13 +21,6 @@ class ZenStyleSheetCache final : public nsISupports { | ||||
|  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. | ||||
| @@ -35,6 +28,15 @@ class ZenStyleSheetCache final : public nsISupports { | ||||
|    */ | ||||
|   auto GetModsSheet() -> StyleSheet*; | ||||
|  | ||||
|   /** | ||||
|    * @brief Rebuild the mods stylesheets. | ||||
|    * This is re-parses the mods stylesheet and applies it to all | ||||
|    * the connected documents. | ||||
|    * @param aContents The contents of the mods stylesheet. | ||||
|    * @returns NS_OK on success, or an error code on failure. | ||||
|    */ | ||||
|   nsresult RebuildModsStylesheets(const nsACString& aContents); | ||||
|  | ||||
|   static auto Singleton() -> ZenStyleSheetCache*; | ||||
|  private: | ||||
|   ZenStyleSheetCache() = default; | ||||
|   | ||||
| @@ -15,17 +15,11 @@ | ||||
|  */ | ||||
| [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(); | ||||
|   void rebuildModsStyles(in ACString aContents); | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -45,61 +45,9 @@ auto nsZenModsBackend::CheckEnabled() -> bool { | ||||
|   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()); | ||||
|   } | ||||
| auto nsZenModsBackend::RebuildModsStyles(const nsACString& aContents) -> nsresult { | ||||
|   // 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; | ||||
|   return GetZenStyleSheetCache()->RebuildModsStylesheets(aContents); | ||||
| } | ||||
|  | ||||
| } // 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<mozilla::dom::ContentParent*> 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); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -840,11 +840,9 @@ | ||||
|       const relativeY = pixelY - rect.top; | ||||
|  | ||||
|       if (!clickedDot && this.dots.length < 1) { | ||||
|         if (this.dots.length === 0) { | ||||
|           this.spawnDot({ x: relativeX, y: relativeY }, true); | ||||
|         } else { | ||||
|           this.spawnDot({ x: relativeX, y: relativeY }); | ||||
|         } | ||||
|         this.spawnDot({ x: relativeX, y: relativeY }, this.dots.length === 0); | ||||
|         // Set brightness to 50% | ||||
|         this.#currentLightness = 50; | ||||
|  | ||||
|         this.updateCurrentWorkspace(true); | ||||
|       } else if (!clickedDot && existingPrimaryDot) { | ||||
|   | ||||
| @@ -16,6 +16,15 @@ | ||||
|       window.addEventListener('ZenWorkspacesUIUpdate', this, true); | ||||
|  | ||||
|       this.initDragAndDrop(); | ||||
|       this.addEventListener('mouseover', (e) => { | ||||
|         if (this.isReorderMode) { | ||||
|           return; | ||||
|         } | ||||
|         const target = e.target.closest('toolbarbutton[zen-workspace-id]'); | ||||
|         if (target) { | ||||
|           this.scrollLeft = target.offsetLeft - 10; | ||||
|         } | ||||
|       }); | ||||
|     } | ||||
|  | ||||
|     initDragAndDrop() { | ||||
| @@ -118,6 +127,7 @@ | ||||
|       } else { | ||||
|         this.removeAttribute('dont-show'); | ||||
|       } | ||||
|       gZenWorkspaces.onWindowResize(); | ||||
|     } | ||||
|  | ||||
|     on_command(event) { | ||||
|   | ||||
| @@ -2872,30 +2872,46 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature { | ||||
|     if (!parent || this._processingResize) { | ||||
|       return; | ||||
|     } | ||||
|     this._processingResize = true; | ||||
|     // Once we are overflowing, we align the buttons to always stay inside the container, | ||||
|     // meaning we need to remove the overflow attribute to reset the width | ||||
|     parent.removeAttribute('icons-overflow'); | ||||
|     requestAnimationFrame(() => { | ||||
|       const overflow = parent.scrollWidth > parent.clientWidth; | ||||
|       parent.toggleAttribute('icons-overflow', overflow); | ||||
|       // The maximum width a button has when it overflows based on the number of buttons | ||||
|       const numButtons = parent.children.length + 1; // +1 to exclude the active button | ||||
|       const maxWidth = 100 / numButtons; | ||||
|       parent.style.setProperty('--zen-overflowed-workspace-button-width', `${maxWidth}%`); | ||||
|       this._processingResize = false; | ||||
|     if (!gZenPinnedTabManager.expandedSidebarMode) { | ||||
|       for (const icon of parent.children) { | ||||
|         if (icon.tagName === 'toolbarbutton') { | ||||
|           icon.style.width = ''; // Reset to default size when in expanded mode | ||||
|         } | ||||
|       } | ||||
|       parent.removeAttribute('icons-overflow'); | ||||
|       return; | ||||
|     } | ||||
|     const maxButtonSize = 30; // IMPORTANT: This should match the CSS size of the icons | ||||
|     const minButtonSize = 15; | ||||
|     const separation = 3; // Space between icons | ||||
|  | ||||
|       // Scroll to the active workspace button if it's not visible | ||||
|       const activeButton = parent.querySelector('.zen-workspace-button.active'); | ||||
|       if (!activeButton) { | ||||
|         return; | ||||
|     // Calculate the total width needed for all icons | ||||
|     const totalWidth = Array.from(parent.children).reduce((width, icon) => { | ||||
|       if (icon.tagName === 'toolbarbutton') { | ||||
|         return width + minButtonSize + separation; | ||||
|       } | ||||
|       const parentRect = parent.getBoundingClientRect(); | ||||
|       const activeRect = activeButton.getBoundingClientRect(); | ||||
|       if (activeRect.left < parentRect.left || activeRect.right > parentRect.right) { | ||||
|         parent.scrollLeft = activeButton.offsetLeft; | ||||
|       return width; | ||||
|     }, 0); | ||||
|  | ||||
|     // Check if the total width exceeds the parent's width | ||||
|     if (totalWidth > parent.clientWidth) { | ||||
|       parent.setAttribute('icons-overflow', 'true'); | ||||
|     } else { | ||||
|       parent.removeAttribute('icons-overflow'); | ||||
|     } | ||||
|  | ||||
|     // Set the width of each icon to the maximum size they can fit on | ||||
|     const widthPerButton = Math.max( | ||||
|       Math.floor( | ||||
|         (parent.clientWidth - separation * (parent.children.length - 1)) / parent.children.length | ||||
|       ), | ||||
|       minButtonSize | ||||
|     ); | ||||
|     for (const icon of parent.children) { | ||||
|       if (icon.tagName === 'toolbarbutton') { | ||||
|         icon.style.width = `${Math.min(widthPerButton, maxButtonSize)}px`; | ||||
|       } | ||||
|     }); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   fixTabInsertLocation(tab) { | ||||
|   | ||||
| @@ -95,6 +95,7 @@ zen-workspace-creation { | ||||
|           --input-bgcolor: transparent; | ||||
|           padding: 0 !important; | ||||
|           width: 100%; | ||||
|           outline: none; | ||||
|         } | ||||
|       } | ||||
|  | ||||
|   | ||||
| @@ -5,7 +5,7 @@ | ||||
|  */ | ||||
|  | ||||
| &:not(:hover) { | ||||
|   width: min(var(--zen-overflowed-workspace-button-width), 25px); | ||||
|   width: min(var(--zen-overflowed-workspace-button-width,10px), 25px) !important; | ||||
|   min-width: 10px; | ||||
|  | ||||
|   &::after { | ||||
| @@ -29,3 +29,7 @@ | ||||
|     display: none; | ||||
|   } | ||||
| } | ||||
|  | ||||
| &:hover { | ||||
|   width: 20px !important; | ||||
| } | ||||
|   | ||||
| @@ -11,8 +11,8 @@ | ||||
|   align-items: center; | ||||
|   display: flex; | ||||
|   font-size: x-small; | ||||
|   padding: 0 3px; | ||||
|   margin: 0; | ||||
|   margin: 0 3px; | ||||
|   padding: 0; | ||||
|   appearance: auto; | ||||
|  | ||||
|   position: relative; | ||||
| @@ -34,7 +34,7 @@ | ||||
|  | ||||
|   & toolbarbutton { | ||||
|     margin: 0; | ||||
|     width: 30px; | ||||
|    max-width: 30px; | ||||
|     height: 30px; | ||||
|     display: flex; | ||||
|     justify-content: center; | ||||
| @@ -84,9 +84,11 @@ | ||||
|  | ||||
|   &[icons-overflow] { | ||||
|     gap: 0 !important; | ||||
|     justify-content: space-between; | ||||
|  | ||||
|     & toolbarbutton { | ||||
|       margin: 0; | ||||
|   background: transparent; | ||||
|     } | ||||
|  | ||||
|     /* Inlcude separately since ther'es a bug in the  | ||||
|   | ||||
| @@ -19,7 +19,7 @@ | ||||
|       "brandShortName": "Zen", | ||||
|       "brandFullName": "Zen Browser", | ||||
|       "release": { | ||||
|         "displayVersion": "1.14b", | ||||
|         "displayVersion": "1.14.1b", | ||||
|         "github": { | ||||
|           "repo": "zen-browser/desktop" | ||||
|         }, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 mr. m
					mr. m