Re-factor the OverlayManager class to use a WeakMap internally

This way we're able to store the `<dialog>` elements directly, which removes the need to use manually specified name-strings thus simplifying both the `OverlayManager` itself and its calling code.
This commit is contained in:
Jonas Jenwald 2022-03-25 14:10:22 +01:00
parent f0aa08b464
commit 923bd52cdb
6 changed files with 48 additions and 66 deletions

View file

@ -162,13 +162,11 @@ function requestAccessToLocalFile(fileUrl, overlayManager, callback) {
reloadIfRuntimeIsUnavailable();
});
}
if (!chromeFileAccessOverlayPromise) {
chromeFileAccessOverlayPromise = overlayManager.register(
"chromeFileAccessDialog",
dialog,
/* canForceClose = */ true
);
}
chromeFileAccessOverlayPromise ||= overlayManager.register(
dialog,
/* canForceClose = */ true
);
chromeFileAccessOverlayPromise.then(function () {
const iconPath = chrome.runtime.getManifest().icons[48];
document.getElementById("chrome-pdfjs-logo-bg").style.backgroundImage =
@ -227,11 +225,11 @@ function requestAccessToLocalFile(fileUrl, overlayManager, callback) {
originalUrl = "file:///fakepath/to/" + encodeURIComponent(file.name);
}
callback(URL.createObjectURL(file), file.size, originalUrl);
overlayManager.close("chromeFileAccessOverlay");
overlayManager.close(dialog);
}
};
overlayManager.open("chromeFileAccessDialog");
overlayManager.open(dialog);
});
}