/// <summary> /// Potentially prompts the user to unload the document. /// </summary> /// <returns>True if unload okay, otherwise false.</returns> internal async Task <Boolean> PromptToUnloadAsync() { var descendants = GetAttachedReferences <IBrowsingContext>(); if (_view.HasEventListener(EventNames.BeforeUnload)) { var unloadEvent = new Event(EventNames.BeforeUnload, bubbles: false, cancelable: true); var shouldCancel = _view.Fire(unloadEvent); _salvageable = false; if (shouldCancel) { var data = new { Document = this, IsCancelled = true, }; await _context.FireAsync(EventNames.ConfirmUnload, data).ConfigureAwait(false); if (data.IsCancelled) { return(false); } } } foreach (var descendant in descendants) { var active = descendant.Active as Document; if (active != null) { var result = await active.PromptToUnloadAsync().ConfigureAwait(false); if (!result) { return(false); } _salvageable = _salvageable && active._salvageable; } } return(true); }