diff --git a/toolkit/content/tests/browser/browser.ini b/toolkit/content/tests/browser/browser.ini index b8648c688be5..a874e2fd78a2 100644 --- a/toolkit/content/tests/browser/browser.ini +++ b/toolkit/content/tests/browser/browser.ini @@ -118,7 +118,6 @@ skip-if = os == "linux" && bits == 64 && os_version = "18.04" # Bug 1614739 [browser_isSynthetic.js] [browser_keyevents_during_autoscrolling.js] [browser_label_textlink.js] -[browser_remoteness_change_listeners.js] [browser_suspend_videos_outside_viewport.js] support-files = file_outside_viewport_videos.html diff --git a/toolkit/content/tests/browser/browser_remoteness_change_listeners.js b/toolkit/content/tests/browser/browser_remoteness_change_listeners.js deleted file mode 100644 index 34c3c4112e99..000000000000 --- a/toolkit/content/tests/browser/browser_remoteness_change_listeners.js +++ /dev/null @@ -1,39 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -/** - * Check that adding progress listeners to a browser doesn't break things - * when switching the remoteness of that browser. - */ -add_task(async function test_remoteness_switch_listeners() { - await BrowserTestUtils.withNewTab("about:support", async function(browser) { - let wpl; - let navigated = new Promise(resolve => { - wpl = { - onLocationChange() { - is(browser.currentURI.spec, "https://example.com/"); - if (browser.currentURI?.spec == "https://example.com/") { - resolve(); - } - }, - QueryInterface: ChromeUtils.generateQI([ - Ci.nsISupportsWeakReference, - Ci.nsIWebProgressListener2, - Ci.nsIWebProgressListener, - ]), - }; - browser.addProgressListener(wpl); - }); - - let loaded = BrowserTestUtils.browserLoaded( - browser, - null, - "https://example.com/" - ); - BrowserTestUtils.loadURI(browser, "https://example.com/"); - await Promise.all([loaded, navigated]); - browser.removeProgressListener(wpl); - }); -}); diff --git a/toolkit/content/widgets/browser-custom-element.js b/toolkit/content/widgets/browser-custom-element.js index 28e821fcf98a..838b266a6e58 100644 --- a/toolkit/content/widgets/browser-custom-element.js +++ b/toolkit/content/widgets/browser-custom-element.js @@ -920,6 +920,22 @@ ); } + /** + * Move the previously-tracked web progress listeners to this 's + * current WebProgress. + */ + restoreProgressListeners() { + let listeners = this.progressListeners; + this.progressListeners = []; + + for (let { weakListener, mask } of listeners) { + let listener = weakListener.get(); + if (listener) { + this.addProgressListener(listener, mask); + } + } + } + onPageHide(aEvent) { if (!this.docShell || !this.fastFind) { return; @@ -1034,6 +1050,7 @@ * the element may not be initialized yet. */ + let oldNavigation = this._remoteWebNavigation; this._remoteWebNavigation = new LazyModules.RemoteWebNavigation(this); // Initialize contentPrincipal to the about:blank principal for this loadcontext @@ -1047,6 +1064,13 @@ // we should re-evaluate the CSP here. this._csp = null; + if (!oldNavigation) { + // If we weren't remote, then we're transitioning from local to + // remote. Add all listeners from the previous to the new + // RemoteWebProgress. + this.restoreProgressListeners(); + } + this.messageManager.loadFrameScript( "chrome://global/content/browser-child.js", true @@ -1095,6 +1119,7 @@ if (!this.isRemoteBrowser) { this._remoteWebNavigation = null; + this.restoreProgressListeners(); this.addEventListener("pagehide", this.onPageHide, true); } }