Backed out changeset 04f7f20bf82e (bug 1921471) for causing bc failures @browser_syncedtabs_sidebar.js.

This commit is contained in:
Adi
2024-11-21 21:25:07 +02:00
parent ba7e26bf67
commit a1f2bdd9ab
10 changed files with 105 additions and 305 deletions

View File

@@ -429,7 +429,6 @@ let JSWINDOWACTORS = {
}, },
matches: ["about:shoppingsidebar"], matches: ["about:shoppingsidebar"],
remoteTypes: ["privilegedabout"], remoteTypes: ["privilegedabout"],
messageManagerGroups: ["shopping-sidebar", "browsers"],
}, },
AboutWelcome: { AboutWelcome: {
@@ -880,7 +879,6 @@ let JSWINDOWACTORS = {
}, },
matches: ["about:shoppingsidebar"], matches: ["about:shoppingsidebar"],
remoteTypes: ["privilegedabout"], remoteTypes: ["privilegedabout"],
messageManagerGroups: ["shopping-sidebar", "browsers"],
}, },
SpeechDispatcher: { SpeechDispatcher: {

View File

@@ -5,7 +5,7 @@
<!-- Bookmarks and history tooltip --> <!-- Bookmarks and history tooltip -->
<tooltip id="bhTooltip" noautohide="true" <tooltip id="bhTooltip" noautohide="true"
class="places-tooltip" class="places-tooltip"
onpopupshowing="return window.browsingContext.topChromeWindow.BookmarksEventHandler.fillInBHTooltip(this, event)" onpopupshowing="return window.top.BookmarksEventHandler.fillInBHTooltip(this, event)"
onpopuphiding="this.removeAttribute('position')"> onpopuphiding="this.removeAttribute('position')">
<box class="places-tooltip-box"> <box class="places-tooltip-box">
<description class="tooltip-label places-tooltip-title"/> <description class="tooltip-label places-tooltip-title"/>

View File

@@ -29,8 +29,7 @@ XPCOMUtils.defineLazyScriptGetter(
var gCumulativeSearches = 0; var gCumulativeSearches = 0;
function init() { function init() {
let top = window.browsingContext.topChromeWindow; let uidensity = window.top.document.documentElement.getAttribute("uidensity");
let uidensity = top.document.documentElement.getAttribute("uidensity");
if (uidensity) { if (uidensity) {
document.documentElement.setAttribute("uidensity", uidensity); document.documentElement.setAttribute("uidensity", uidensity);
} }

View File

@@ -27,7 +27,6 @@
remote="true" remote="true"
src="about:shoppingsidebar" src="about:shoppingsidebar"
type="content" type="content"
messagemanagergroup="shopping-sidebar"
/> />
`; `;
} }

View File

@@ -158,12 +158,11 @@ var SidebarController = {
"viewReviewCheckerSidebar", "viewReviewCheckerSidebar",
{ {
elementId: "sidebar-switcher-review-checker", elementId: "sidebar-switcher-review-checker",
url: "about:shoppingsidebar", url: "chrome://browser/content/shopping/shopping.html",
menuId: "menu_reviewCheckerSidebar", menuId: "menu_reviewCheckerSidebar",
menuL10nId: "menu-view-review-checker", menuL10nId: "menu-view-review-checker",
revampL10nId: "sidebar-menu-review-checker-label", revampL10nId: "sidebar-menu-review-checker-label",
iconUrl: "chrome://browser/content/shopping/assets/shopping.svg", iconUrl: "chrome://browser/content/shopping/assets/shopping.svg",
remoteType: E10SUtils.PRIVILEGEDABOUT_REMOTE_TYPE,
} }
); );
} }
@@ -218,14 +217,6 @@ var SidebarController = {
} }
return (this._browser = document.getElementById("sidebar")); return (this._browser = document.getElementById("sidebar"));
}, },
set browser(browser) {
let currentBrowser = this.browser;
currentBrowser.destroy();
currentBrowser.replaceWith(browser);
this._browser = browser;
},
POSITION_START_PREF: "sidebar.position_start", POSITION_START_PREF: "sidebar.position_start",
DEFAULT_SIDEBAR_ID: "viewBookmarksSidebar", DEFAULT_SIDEBAR_ID: "viewBookmarksSidebar",
TOOLS_PREF: "sidebar.main.tools", TOOLS_PREF: "sidebar.main.tools",
@@ -696,8 +687,9 @@ var SidebarController = {
this.hideSwitcherPanel(); this.hideSwitcherPanel();
if (!this.browser.isRemoteBrowser) { let content = SidebarController.browser.contentWindow;
this.browser.contentWindow.updatePosition?.(); if (content && content.updatePosition) {
content.updatePosition();
} }
}, },
@@ -876,10 +868,8 @@ var SidebarController = {
* window, only when the user opens the sidebar. * window, only when the user opens the sidebar.
*/ */
_fireFocusedEvent() { _fireFocusedEvent() {
if (!this.browser.isRemoteBrowser) { let event = new CustomEvent("SidebarFocused", { bubbles: true });
let event = new CustomEvent("SidebarFocused", { bubbles: true }); this.browser.contentWindow.dispatchEvent(event);
this.browser.contentWindow.dispatchEvent(event);
}
}, },
/** /**
@@ -1495,218 +1485,92 @@ var SidebarController = {
* @param {string} commandID ID of the sidebar. * @param {string} commandID ID of the sidebar.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async _show(commandID) { _show(commandID) {
if (this.sidebarRevampEnabled) {
this.sidebarContainer.hidden = false;
this._box.dispatchEvent(
new CustomEvent("sidebar-show", { detail: { viewId: commandID } })
);
// Whenever a panel is shown, the sidebar is collapsed. Upon hiding
// that panel afterwards, `expanded` reverts back to what it was prior
// to calling `show()`. Thus, we store the expanded state at this point.
this._previousExpandedState = this.sidebarMain.expanded;
this.toggleExpanded(false);
} else {
this.hideSwitcherPanel();
}
this.selectMenuItem(commandID);
this._box.hidden = this._splitter.hidden = false;
this._box.setAttribute("checked", "true");
this._box.setAttribute("sidebarcommand", commandID);
let { icon, url, title, sourceL10nEl, contextMenuId, remoteType } =
this.sidebars.get(commandID);
if (icon) {
this._switcherTarget.style.setProperty(
"--webextension-menuitem-image",
icon
);
} else {
this._switcherTarget.style.removeProperty(
"--webextension-menuitem-image"
);
}
if (contextMenuId) {
this._box.setAttribute("context", contextMenuId);
} else {
this._box.removeAttribute("context");
}
// use to live update <tree> elements if the locale changes
this.lastOpenedId = commandID;
// These title changes only apply to the old sidebar menu
if (!this.sidebarRevampEnabled) {
this.title = title;
// Keep the title element in the switcher in sync with any l10n changes.
this.observeTitleChanges(sourceL10nEl);
}
await this._loadURL(url, remoteType);
// Now that the currentId is updated, fire a show event.
this._fireShowEvent();
this._recordBrowserSize();
},
/**
* Loads the given URL into the browser.
*
* If the current sidebar browser doesn't match the remoteType
* of the new URL, the browser will be replaced with one that does.
*
* @param {string} url to load.
* @param {string} [remoteType] of the content.
* @returns {Promise<void>}
*/
async _loadURL(url, remoteType) {
let targetURI = makeURI(url);
if (
remoteType &&
(!this.browser.isRemoteBrowser || this.browser.remoteType !== remoteType)
) {
this.browser = this._createBrowser({ remoteType });
} else if (!remoteType && this.browser.hasAttribute("remote")) {
this.browser = this._createBrowser();
}
let loadPromise;
if (this.browser.isRemoteBrowser) {
this.browser.loadURI(targetURI, {
triggeringPrincipal:
Services.scriptSecurityManager.getSystemPrincipal(),
});
loadPromise = this._hasProgressStopped(targetURI);
} else {
this.browser.setAttribute("src", url); // kick off async load
loadPromise = this._hasLoaded(url);
}
await loadPromise;
},
/**
* Creates a new browser, either non-remote or remote
* with the given remoteType.
*
* @param {object} [options]
* @param {string} [options.remoteType] to set for the browser.
* @returns {Browser}
*/
_createBrowser(options = { remoteType: E10SUtils.NOT_REMOTE }) {
let { remoteType } = options;
let browser = document.createXULElement("browser");
browser.setAttribute("id", "sidebar");
browser.setAttribute("autoscroll", "false");
browser.setAttribute("disablehistory", "true");
browser.setAttribute("disablefullscreen", "true");
browser.setAttribute("tooltip", "aHTMLTooltip");
if (remoteType) {
browser.setAttribute("type", "content");
browser.setAttribute("remote", "true");
browser.setAttribute("remoteType", remoteType);
browser.setAttribute("maychangeremoteness", "true");
browser.setAttribute("messagemanagergroup", "sidebar-browsers");
}
return browser;
},
/**
* Wait for a URL to have loaded or unloaded in the sidebar browser.
*
* @param {string} url to check has loaded.
* @returns {Promise<void>}
*/
async _hasLoaded(url) {
return new Promise(resolve => { return new Promise(resolve => {
if ( if (this.sidebarRevampEnabled) {
this.browser.contentDocument.location.href == url && this.sidebarContainer.hidden = false;
this.browser.contentDocument.readyState === "complete" this._box.dispatchEvent(
) { new CustomEvent("sidebar-show", { detail: { viewId: commandID } })
resolve(); );
return;
// Whenever a panel is shown, the sidebar is collapsed. Upon hiding
// that panel afterwards, `expanded` reverts back to what it was prior
// to calling `show()`. Thus, we store the expanded state at this point.
this._previousExpandedState = this.sidebarMain.expanded;
this.toggleExpanded(false);
} else {
this.hideSwitcherPanel();
} }
// make sure to clear the timeout if the load is aborted this.selectMenuItem(commandID);
this.browser.addEventListener("unload", () => { this._box.hidden = this._splitter.hidden = false;
if (this.browser.loadingTimerID) {
clearTimeout(this.browser.loadingTimerID); this._box.setAttribute("checked", "true");
delete this.browser.loadingTimerID; this._box.setAttribute("sidebarcommand", commandID);
resolve();
} let { icon, url, title, sourceL10nEl, contextMenuId } =
}); this.sidebars.get(commandID);
this.browser.addEventListener( if (icon) {
"load", this._switcherTarget.style.setProperty(
() => { "--webextension-menuitem-image",
// We're handling the 'load' event before it bubbles up to the usual icon
// (non-capturing) event handlers. Let it bubble up before resolving. );
this.browser.loadingTimerID = setTimeout(() => { } else {
this._switcherTarget.style.removeProperty(
"--webextension-menuitem-image"
);
}
if (contextMenuId) {
this._box.setAttribute("context", contextMenuId);
} else {
this._box.removeAttribute("context");
}
// use to live update <tree> elements if the locale changes
this.lastOpenedId = commandID;
// These title changes only apply to the old sidebar menu
if (!this.sidebarRevampEnabled) {
this.title = title;
// Keep the title element in the switcher in sync with any l10n changes.
this.observeTitleChanges(sourceL10nEl);
}
this.browser.setAttribute("src", url); // kick off async load
if (this.browser.contentDocument.location.href != url) {
// make sure to clear the timeout if the load is aborted
this.browser.addEventListener("unload", () => {
if (this.browser.loadingTimerID) {
clearTimeout(this.browser.loadingTimerID);
delete this.browser.loadingTimerID; delete this.browser.loadingTimerID;
resolve(); resolve();
}, 0);
},
{ capture: true, once: true }
);
});
},
/**
* Wait for a URI's progress to have stopped after loading
* in a remote sidebar browser.
*
* @param {URI} targetURI to check has loaded.
* @returns {Promise<void>}
*/
async _hasProgressStopped(targetURI) {
return new Promise(resolve => {
let b = this.browser;
if (
b.currentURI?.equalsExceptRef(targetURI) &&
!b.webProgress.isLoadingDocument
) {
resolve();
return;
}
let referenceKeeper = new Set();
const { STATE_IS_WINDOW, STATE_STOP } = Ci.nsIWebProgressListener;
let progListener = {
onStateChange: (webProgress, request, flags, _status) => {
if (
flags & STATE_IS_WINDOW &&
flags & STATE_STOP &&
webProgress.isTopLevel &&
(request?.originalURI?.equalsExceptRef(targetURI) ||
b.currentURI?.equalsExceptRef(targetURI))
) {
resolve();
referenceKeeper.delete(filter);
b.removeProgressListener(filter);
} }
}, });
QueryInterface: ChromeUtils.generateQI([ this.browser.addEventListener(
"nsIWebProgressListener", "load",
"nsISupportsWeakReference", () => {
]), // We're handling the 'load' event before it bubbles up to the usual
}; // (non-capturing) event handlers. Let it bubble up before resolving.
const filter = Cc[ this.browser.loadingTimerID = setTimeout(() => {
"@mozilla.org/appshell/component/browser-status-filter;1" delete this.browser.loadingTimerID;
].createInstance(Ci.nsIWebProgress); resolve();
filter.addProgressListener(
progListener, // Now that the currentId is updated, fire a show event.
Ci.nsIWebProgress.NOTIFY_STATE_WINDOW this._fireShowEvent();
); this._recordBrowserSize();
referenceKeeper.add(filter); }, 0);
this.browser.addProgressListener( },
filter, { capture: true, once: true }
Ci.nsIWebProgress.NOTIFY_STATE_WINDOW );
); } else {
resolve();
// Now that the currentId is updated, fire a show event.
this._fireShowEvent();
this._recordBrowserSize();
}
}); });
}, },
@@ -1736,22 +1600,12 @@ var SidebarController = {
this.selectMenuItem(""); this.selectMenuItem("");
// Replace the document currently displayed in the sidebar with about:blank // Replace the document currently displayed in the sidebar with about:blank
// so that we can free memory by unloading the page. // so that we can free memory by unloading the page. We need to explicitly
if (this.browser.isRemoteBrowser) { // create a new content viewer because the old one doesn't get destroyed
let nullPrincipal = Services.scriptSecurityManager.createNullPrincipal( // until about:blank has loaded (which does not happen as long as the
{} // element is hidden).
); this.browser.setAttribute("src", "about:blank");
this.browser.loadURI(Services.io.newURI("about:blank"), { this.browser.docShell?.createAboutBlankDocumentViewer(null, null);
triggeringPrincipal: nullPrincipal,
});
this.browser.createAboutBlankDocumentViewer(nullPrincipal, nullPrincipal);
} else {
// We need to explicitly create a new content viewer because the old one
// doesn't get destroyed until about:blank has loaded (which does not happen
// as long as the element is hidden).
this.browser.setAttribute("src", "about:blank");
this.browser.docShell?.createAboutBlankDocumentViewer(null, null);
}
this._box.removeAttribute("checked"); this._box.removeAttribute("checked");
this._box.removeAttribute("context"); this._box.removeAttribute("context");

View File

@@ -39,7 +39,7 @@ export class SidebarPage extends MozLitElement {
} }
get topWindow() { get topWindow() {
return this.ownerGlobal.browsingContext.topChromeWindow; return this.ownerGlobal.top;
} }
get sidebarController() { get sidebarController() {

View File

@@ -41,8 +41,6 @@ run-if = ["os == 'mac'"] # Mac only feature
["browser_sidebar_prefs.js"] ["browser_sidebar_prefs.js"]
["browser_sidebar_remote.js"]
["browser_syncedtabs_sidebar.js"] ["browser_syncedtabs_sidebar.js"]
["browser_toolbar_sidebar_button.js"] ["browser_toolbar_sidebar_button.js"]

View File

@@ -10,8 +10,8 @@ const TAB_DIRECTION_PREF = "sidebar.verticalTabs";
async function showCustomizePanel(win) { async function showCustomizePanel(win) {
await win.SidebarController.show("viewCustomizeSidebar"); await win.SidebarController.show("viewCustomizeSidebar");
return TestUtils.waitForCondition(() => { const document = win.SidebarController.browser.contentDocument;
const document = win.SidebarController.browser.contentDocument; return TestUtils.waitForCondition(async () => {
const component = document.querySelector("sidebar-customize"); const component = document.querySelector("sidebar-customize");
if (!component?.positionInputs || !component?.visibilityInputs) { if (!component?.positionInputs || !component?.visibilityInputs) {
return false; return false;
@@ -122,13 +122,12 @@ add_task(async function test_customize_not_added_in_menubar() {
add_task(async function test_manage_preferences_navigation() { add_task(async function test_manage_preferences_navigation() {
const win = await BrowserTestUtils.openNewBrowserWindow(); const win = await BrowserTestUtils.openNewBrowserWindow();
await showCustomizePanel(win); const { SidebarController } = win;
const sidebarBox = win.document.getElementById("sidebar-box"); const { contentWindow } = SidebarController.browser;
await BrowserTestUtils.waitForCondition( const sidebar = document.querySelector("sidebar-main");
() => BrowserTestUtils.isVisible(sidebarBox), ok(sidebar, "Sidebar is shown.");
"Sidebar panel is visible" await sidebar.updateComplete;
); await toggleSidebarPanel(win, "viewCustomizeSidebar");
let customizeDocument = win.SidebarController.browser.contentDocument; let customizeDocument = win.SidebarController.browser.contentDocument;
const customizeComponent = const customizeComponent =
customizeDocument.querySelector("sidebar-customize"); customizeDocument.querySelector("sidebar-customize");
@@ -139,7 +138,7 @@ add_task(async function test_manage_preferences_navigation() {
EventUtils.synthesizeMouseAtCenter( EventUtils.synthesizeMouseAtCenter(
manageSettings.querySelector("a"), manageSettings.querySelector("a"),
{}, {},
customizeDocument.ownerGlobal contentWindow
); );
await BrowserTestUtils.waitForCondition( await BrowserTestUtils.waitForCondition(
() => () =>

View File

@@ -1,47 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
https://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_remote_sidebar_browser() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.integratedSidebar", true],
["sidebar.main.tools", "reviewchecker,syncedtabs,history"],
],
});
const sidebar = document.querySelector("sidebar-main");
ok(sidebar, "Sidebar is shown.");
// Non-remote sidebar
await SidebarController.show("viewHistorySidebar");
ok(SidebarController.browser, "Sidebar browser is shown.");
ok(
!SidebarController.browser.hasAttribute("remote"),
"Sidebar browser is not remote."
);
// Remote content sidebar
await SidebarController.show("viewReviewCheckerSidebar");
ok(SidebarController.browser, "Sidebar browser is shown.");
Assert.equal(
SidebarController.browser.getAttribute("remote"),
"true",
"Sidebar browser is remote."
);
Assert.equal(
SidebarController.browser.getAttribute("type"),
"content",
"Sidebar browser is remote."
);
// Another non-remote sidebar
await SidebarController.show("viewTabsSidebar");
ok(SidebarController.browser, "Sidebar browser is shown.");
ok(
!SidebarController.browser.hasAttribute("remote"),
"Sidebar browser is not remote."
);
await SpecialPowers.popPrefEnv();
});

View File

@@ -274,7 +274,7 @@ LightweightThemeConsumer.prototype = {
// If enabled, apply the dark theme variant to private browsing windows. // If enabled, apply the dark theme variant to private browsing windows.
if ( if (
!Services.prefs.getBoolPref("browser.theme.dark-private-windows") || !Services.prefs.getBoolPref("browser.theme.dark-private-windows") ||
!this._win.browsingContext.usePrivateBrowsing || !lazy.PrivateBrowsingUtils.isWindowPrivate(this._win) ||
lazy.PrivateBrowsingUtils.permanentPrivateBrowsing lazy.PrivateBrowsingUtils.permanentPrivateBrowsing
) { ) {
return false; return false;