From f239744191e76402414f6e8f07fdc59863d7a6c8 Mon Sep 17 00:00:00 2001
From: Domenic Denicola
cancelAction being to return the
- result of firing an event named cancelAction given
+ canPreventClose being to return the result of firing an event named cancel
at this, with the cancelable
attribute initialized to true.
closeAction being to close the dialog given this and null.
A window, a Window
.
A cancel action, a list of steps. These - steps can never throw an exception, and return either true (to indicate that the caller will - proceed to the close action) or false (to - indicate that the caller will bail out).
A cancel action, an algorithm accepting a + boolean argument and returning a boolean. The argument indicates whether or not the cancel + action algorithm can prevent the close request from proceeding via the algorithm's return value. + If the boolean argument is true, then the algorithm can return either true to indicate that the + caller will proceed to the close action, or + false to indicate that the caller will bail out. If the argument is false, then the return value + is always false. This algorithm can never throw an exception.
A close action, a list of steps. These - steps can never throw an exception.
A close action, an algorithm accepting no + arguments and returning nothing. This algorithm can never throw an exception.
An is running cancel action boolean.
If window's associated
Document
is not fully active, then return true.
If window's close watcher manager's groups's size is less than - window's close watcher manager's allowed number of groups, and window has - history-action activation, then:
+Let canPreventClose be true if window's close watcher + manager's groups's size is less than window's close watcher manager's allowed number of groups, and + window has history-action activation; otherwise false.
Set closeWatcher's is running - cancel action to true.
Set closeWatcher's is running + cancel action to true.
Let shouldContinue be the result of running closeWatcher's cancel action.
Let shouldContinue be the result of running closeWatcher's cancel action given + canPreventClose.
Set closeWatcher's is running - cancel action to false.
Set closeWatcher's is running + cancel action to false.
If shouldContinue is false, then:
+If shouldContinue is false, then:
-Consume history-action user activation given window.
Assert: canPreventClose is true.
Return false.
Consume history-action user activation given window.
Return false.
Note that since these substeps consume history-action user activation, requesting to close a - close watcher twice without any intervening user activation will skip - these substeps.
+ close watcher twice without any intervening user activation will + result in canPreventClose being false the second time.Close closeWatcher.
cancelAction being to return the
- result of firing an event named cancelAction given
+ canPreventClose being to return the result of firing an event named cancel
at this, with the cancelable
attribute initialized to true.
closeAction being to fire an event named close
@@ -82494,7 +82500,7 @@ picker.querySelector('.close-button').onclick = () => watcher.requestClose();CloseWatcher from being destroying. A typical use case is as follows:
watcher.oncancel = async (e) => {
- if (hasUnsavedData) {
+ if (hasUnsavedData && e.cancelable) {
e.preventDefault();
const userReallyWantsToClose = await askForConfirmation("Are you sure you want to close?");
@@ -82505,11 +82511,13 @@ picker.querySelector('.close-button').onclick = () => watcher.requestClose();
- For abuse prevention purposes, this event only fires if the page has history-action
+ For abuse prevention purposes, this event is only cancelable
if the page has history-action
activation, which will be lost after any given close request. This ensures
that if the user sends a close request twice in a row without any intervening user activation,
- the request definitely succeeds; the second request ignores the cancel
event handler and immediately closes the
+ the request definitely succeeds; the second request ignores any cancel
event handler's attempt to call preventDefault()
and proceeds to close the
CloseWatcher
.