chore: Cherry pick commits, b=no-bug, c=no-component

This commit is contained in:
mr. m
2026-02-21 00:20:15 +01:00
parent 030ed7abf4
commit c8b0c2d4bd
3 changed files with 17 additions and 38 deletions

View File

@@ -128,7 +128,7 @@ index edb0482f0bfb22c70a585b0770e5b0437983779e..109e9eb18b90c650caff1287caef04dc
+ if (this._zenHandleUrlbarClose) {
+ this._zenHandleUrlbarClose();
+ } else if (!this._untrimmedValue) {
+ } else if (!this._untrimmedValue || this.searchMode) {
+ // Restore the current page URL when the urlbar is empty on blur
+ this.handleRevert();
+ }

View File

@@ -194,7 +194,7 @@ export class nsZenSessionManager {
} catch {
/* ignore errors reading recovery data */
}
if (!data.recoverYData) {
if (!data.recoveryData) {
try {
data.recoveryData = await IOUtils.readJSON(
PathUtils.join(

View File

@@ -620,15 +620,9 @@ class nsZenWindowSync {
this.log(`Cannot swap browsers, other tab ${aOtherTab.id} is closing`);
return;
}
let promise = this.#maybeFlushTabState(aOtherTab);
await this.#styleSwapedBrowsers(
aOurTab,
aOtherTab,
() => {
this.#swapBrowserDocShellsInner(aOurTab, aOtherTab);
},
promise
);
await this.#styleSwapedBrowsers(aOurTab, aOtherTab, () => {
this.#swapBrowserDocShellsInner(aOurTab, aOtherTab);
});
}
/**
@@ -708,28 +702,23 @@ class nsZenWindowSync {
);
return null;
}
// See https://github.com/zen-browser/desktop/issues/11851, swapping the browsers
// don't seem to update the state's cache properly, leading to issues when restoring
// the session later on.
let tabStateEntries = this.#getTabEntriesFromCache(aOtherTab);
const setStateToTab = () => {
if (!tabStateEntries?.entries.length) {
this.log(`Error: No tab state entries found for tab ${aOurTab.id} during swap`);
return;
}
lazy.TabStateCache.update(aOurTab.linkedBrowser.permanentKey, {
history: Cu.cloneInto(tabStateEntries, {}),
});
};
// Running `swapBrowsersAndCloseOther` doesn't expect us to use the tab after
// the operation, so it doesn't really care about cleaning up the other tab.
// We need to make a new tab progress listener for the other tab after the swap.
this.#withRestoreTabProgressListener(
aOtherTab,
() => {
setStateToTab();
this.log(`Swapping docshells between windows for tab ${aOurTab.id}`);
aOurTab.ownerGlobal.gBrowser.swapBrowsersAndCloseOther(aOurTab, aOtherTab, false);
// Swap permanent keys
const ourPermanentKey = aOurTab.linkedBrowser.permanentKey;
const otherPermanentKey = aOtherTab.linkedBrowser.permanentKey;
aOurTab.linkedBrowser.permanentKey = otherPermanentKey;
aOtherTab.linkedBrowser.permanentKey = ourPermanentKey;
aOurTab.permanentKey = otherPermanentKey;
aOtherTab.permanentKey = ourPermanentKey;
// Since we are moving progress listeners around, there's a chance that we
// trigger a load while making the switch, and since we remove the previous
// tab's listeners, the other browser window will never get the 'finish load' event
@@ -772,14 +761,6 @@ class nsZenWindowSync {
aOurTab.ownerGlobal.gBrowser._adjustFocusAfterTabSwitch(aOurTab);
aOurTab.linkedBrowser.docShellIsActive = true;
}
// Ensure the tab's state is flushed after the swap. By doing this,
// we can re-schedule another session store delayed process to fire.
// It's also important to note that if we don't flush the state here,
// we would start receiving invalid history changes from the the incorrect
// browser view that was just swapped out.
return this.#maybeFlushTabState(aOurTab).finally(() => {
setStateToTab();
});
}
/**
@@ -788,9 +769,8 @@ class nsZenWindowSync {
* @param {object} aOurTab - The tab in the current window.
* @param {object} aOtherTab - The tab in the other window.
* @param {Function|undefined} callback - The callback function to execute after styling.
* @param {Promise|null} promiseToWait - A promise to wait for before executing the callback.
*/
#styleSwapedBrowsers(aOurTab, aOtherTab, callback = undefined, promiseToWait = null) {
#styleSwapedBrowsers(aOurTab, aOtherTab, callback = undefined) {
const ourBrowser = aOurTab.linkedBrowser;
const otherBrowser = aOtherTab.linkedBrowser;
// eslint-disable-next-line no-async-promise-executor
@@ -817,8 +797,7 @@ class nsZenWindowSync {
};
});
let promise = this.#createPseudoImageForBrowser(otherBrowser, mySrc);
await Promise.all([promiseToWait, promise]);
await this.#createPseudoImageForBrowser(otherBrowser, mySrc);
callback();
lazy.setTimeout(() => {
otherBrowser.setAttribute("zen-pseudo-hidden", "true");
@@ -1006,7 +985,7 @@ class nsZenWindowSync {
* @returns {Promise} A promise that resolves when the operation is complete.
*/
#maybeFlushTabState(aTab) {
if (!aTab.linkedBrowser) {
if (!aTab.linkedBrowser || aTab.hasAttribute("pending")) {
return Promise.resolve();
}
return lazy.TabStateFlusher.flush(aTab.linkedBrowser);