From 1ef98896a86abe1491d0911c9ac1cccd07527114 Mon Sep 17 00:00:00 2001 From: pbz Date: Tue, 8 Sep 2020 16:31:19 +0000 Subject: [PATCH] Bug 1662962 - Defer favicon load for the protocol handler dialog. r=Gijs Dialogs loaded via SubDialog only show once they are loaded. This defers inserting the favicon URIs into the DOM until after the load event, so that slow loads don't keep the dialog hidden. Differential Revision: https://phabricator.services.mozilla.com/D89462 --- toolkit/mozapps/handling/content/dialog.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/toolkit/mozapps/handling/content/dialog.js b/toolkit/mozapps/handling/content/dialog.js index ace5de0371a9..264438889867 100644 --- a/toolkit/mozapps/handling/content/dialog.js +++ b/toolkit/mozapps/handling/content/dialog.js @@ -78,6 +78,10 @@ window.addEventListener("DOMContentLoaded", () => dialog.initialize(), { once: true, }); +let loadPromise = new Promise(resolve => { + window.addEventListener("load", resolve, { once: true }); +}); + var dialog = { // Member Variables @@ -186,10 +190,14 @@ var dialog = { elm.setAttribute("name", app.name); elm.obj = app; + // We defer loading the favicon so it doesn't delay load. The dialog is + // opened in a SubDialog which will only show on window load. if (app instanceof Ci.nsILocalHandlerApp) { // See if we have an nsILocalHandlerApp and set the icon let uri = Services.io.newFileURI(app.executable); - elm.setAttribute("image", "moz-icon://" + uri.spec + "?size=32"); + loadPromise.then(() => { + elm.setAttribute("image", "moz-icon://" + uri.spec + "?size=32"); + }); } else if (app instanceof Ci.nsIWebHandlerApp) { let uri = Services.io.newURI(app.uriTemplate); if (/^https?$/.test(uri.scheme)) { @@ -199,7 +207,9 @@ var dialog = { // and users won't visit the handler's URL template, they'll only // visit URLs derived from that template (i.e. with %s in the template // replaced by the URL of the content being handled). - elm.setAttribute("image", uri.prePath + "/favicon.ico"); + loadPromise.then(() => { + elm.setAttribute("image", uri.prePath + "/favicon.ico"); + }); } elm.setAttribute("description", uri.prePath);