Files
sousa-gecko/dom/filesystem/tests/script_promptHandler.js
T
Emilio Cobos Álvarez e833a1757b Bug 2033243 - Replace ownerGlobal with documentGlobal, and stop exposing ownerGlobal to JS. r=firefox-desktop-core-reviewers ,webidl,joschmidt,perftest-reviewers,sparky,smaug,mossop ,webidl,joschmidt,perftest-reviewers,sparky,smaug,mossop
Bug 2033191 made sure we only call ownerGlobal on nodes.

As per the discussion in dev-platform, the front-end ~always wants
.documentGlobal. This removes ownerGlobal from the bindings. Following
patch will rename internal GetOwnerGlobal in gecko to GetRelevantGlobal
as per the HTML spec terminology.

Differential Revision: https://phabricator.services.mozilla.com/D297183
2026-05-02 22:04:13 +00:00

55 lines
1.5 KiB
JavaScript

let dialogObserverTopic = "common-dialog-loaded";
function waitForButtonEnabledState(button) {
return new Promise(resolve => {
// Check if the button is already enabled (not disabled)
if (!button.disabled) {
resolve();
return;
}
// Create a MutationObserver instance
let win = button.documentGlobal;
let { MutationObserver } = win;
const observer = new MutationObserver(mutationsList => {
for (const mutation of mutationsList) {
if (
mutation.type === "attributes" &&
mutation.attributeName === "disabled"
) {
if (!button.disabled) {
// Resolve the promise when the button is enabled
observer.disconnect(); // Stop observing
resolve();
}
}
}
});
// Start observing the button for changes to the 'disabled' attribute
observer.observe(button, {
attributes: true,
attributeFilter: ["disabled"],
});
});
}
async function dialogObserver(subj) {
let dialog = subj.document.querySelector("dialog");
let acceptButton = dialog.getButton("accept");
await waitForButtonEnabledState(acceptButton);
subj.document.querySelector("dialog").acceptDialog();
sendAsyncMessage("promptAccepted");
}
addMessageListener("init", () => {
Services.obs.addObserver(dialogObserver, dialogObserverTopic);
sendAsyncMessage("initDone");
});
addMessageListener("cleanup", () => {
Services.obs.removeObserver(dialogObserver, dialogObserverTopic);
sendAsyncMessage("cleanupDone");
});