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
This commit is contained in:
pbz 2020-09-08 16:31:19 +00:00
Родитель ebe9679c75
Коммит 1ef98896a8
1 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -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);