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
55 lines
1.5 KiB
JavaScript
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");
|
|
});
|