morgan pushed to branch mullvad-browser-140.5.0esr-15.0-1 at The Tor Project / Applications / Mullvad Browser Commits: 4469cbad by Henry Wilkes at 2025-11-17T10:41:33+00:00 fixup! MB 39: Add home page about:mullvad-browser MB 486: Delay the update data for preloaded about:mullvad-browser pages. - - - - - 3 changed files: - browser/components/mullvad-browser/AboutMullvadBrowserChild.sys.mjs - browser/components/mullvad-browser/AboutMullvadBrowserParent.sys.mjs - browser/components/tabbrowser/NewTabPagePreloading.sys.mjs Changes: ===================================== browser/components/mullvad-browser/AboutMullvadBrowserChild.sys.mjs ===================================== @@ -5,13 +5,34 @@ export class AboutMullvadBrowserChild extends JSWindowActorChild { handleEvent(event) { switch (event.type) { case "DOMContentLoaded": - this.sendQuery("AboutMullvadBrowser:GetUpdateData").then(data => { - const updateEvent = new this.contentWindow.CustomEvent("UpdateData", { - detail: Cu.cloneInto(data, this.contentWindow), - }); - this.contentWindow.dispatchEvent(updateEvent); + this.sendQuery("AboutMullvadBrowser:GetUpdateData").then(response => { + if (response.delayed) { + // Wait for DelayedUpdateData. + return; + } + this.#dispatchUpdateData(response.updateData); }); break; } } + + receiveMessage(message) { + switch (message.name) { + case "AboutMullvadBrowser:DelayedUpdateData": + this.#dispatchUpdateData(message.data); + break; + } + } + + /** + * Send the update data to the page. + * + * @param {object} data - The data to send. + */ + #dispatchUpdateData(data) { + const updateEvent = new this.contentWindow.CustomEvent("UpdateData", { + detail: Cu.cloneInto(data, this.contentWindow), + }); + this.contentWindow.dispatchEvent(updateEvent); + } } ===================================== browser/components/mullvad-browser/AboutMullvadBrowserParent.sys.mjs ===================================== @@ -2,30 +2,73 @@ * Actor parent class for the about:mullvad-browser page. */ export class AboutMullvadBrowserParent extends JSWindowActorParent { - receiveMessage(message) { + /** + * Whether this instance has a preloaded browser. + * + * @type {boolean} + */ + #preloaded = false; + + /** + * Method to be called when the browser corresponding to this actor has its + * preloadedState attribute removed. + */ + preloadedRemoved() { + if (!this.#preloaded) { + return; + } + this.#preloaded = false; + // Send in the initial data now that the page is actually going to be + // visible. + this.sendAsyncMessage( + "AboutMullvadBrowser:DelayedUpdateData", + this.#getUpdateData() + ); + } + + /** + * Get the update data for the page. + * + * @returns {object?} - The update data, or `null` if no update should be + * shown. + */ + #getUpdateData() { const shouldNotifyPref = "mullvadbrowser.post_update.shouldNotify"; + if (!Services.prefs.getBoolPref(shouldNotifyPref, false)) { + return null; + } + Services.prefs.clearUserPref(shouldNotifyPref); + // Try use the same URL as the about dialog. See mullvad-browser#411. + let updateURL = Services.urlFormatter.formatURLPref( + "app.releaseNotesURL.aboutDialog" + ); + if (updateURL === "about:blank") { + updateURL = Services.urlFormatter.formatURLPref( + "startup.homepage_override_url" + ); + } + + return { + version: Services.prefs.getCharPref( + "browser.startup.homepage_override.mullvadbrowser.version" + ), + url: updateURL, + }; + } + + receiveMessage(message) { switch (message.name) { case "AboutMullvadBrowser:GetUpdateData": { - if (!Services.prefs.getBoolPref(shouldNotifyPref, false)) { - return Promise.resolve(null); - } - Services.prefs.clearUserPref(shouldNotifyPref); - // Try use the same URL as the about dialog. See mullvad-browser#411. - let updateURL = Services.urlFormatter.formatURLPref( - "app.releaseNotesURL.aboutDialog" - ); - if (updateURL === "about:blank") { - updateURL = Services.urlFormatter.formatURLPref( - "startup.homepage_override_url" - ); + const browser = this.browsingContext.top.embedderElement; + if (browser?.getAttribute("preloadedState") === "preloaded") { + // Wait until the page is actually about to be shown before sending + // the initial data. + // Otherwise the preloaded page might grab the updateData even though + // it won't be shown as the landing page. See mullvad-browser#486. + this.#preloaded = true; + return Promise.resolve({ delayed: true }); } - - return Promise.resolve({ - version: Services.prefs.getCharPref( - "browser.startup.homepage_override.mullvadbrowser.version" - ), - url: updateURL, - }); + return Promise.resolve({ updateData: this.#getUpdateData() }); } } return undefined; ===================================== browser/components/tabbrowser/NewTabPagePreloading.sys.mjs ===================================== @@ -178,6 +178,17 @@ export let NewTabPagePreloading = { this.browserCounts[countKey]--; browser.removeAttribute("preloadedState"); browser.setAttribute("autocompletepopup", "PopupAutoComplete"); + // Copied from tor-browser. See mullvad-browser#486. + // Let a preloaded about:mullvad-browser page know that it is no longer + // preloaded (about to be shown). + try { + browser.browsingContext?.currentWindowGlobal + ?.getActor("AboutMullvadBrowser") + .preloadedRemoved(); + } catch { + // Not an about:mullvad-browser page with an AboutMullvadBrowserParent + // instance. + } } return browser; View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/4469... -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/4469... You're receiving this email because of your account on gitlab.torproject.org.
participants (1)
-
morgan (@morgan)