beforeunload is fired when a page is about to be closed, to ask the user for confirmation. This happens when reloading a page, when navigation to another page or when the page is closed by a user action (a tab or window closed). In the first two cases, the event is automatically fired by WebCore, but in the case of a user action we need additional API to ensure the event is fired before the page is closed.
Created attachment 242264 [details]
Don't forget to set mnemonics on the buttons: "_Stay on Page" and "_Leave Page" seem good.
Ping reviewers. I know this is a so annoying web feature, we can add a setting and disable it by default, so that apps need to explicitly enable it if they really want to irritate their users.
I think, based on the complaints I've heard from users, we should just have it enabled by default. I don't think many sites take advantage of this to create unnecessary "are you sure you want to leave" messages nowadays, except when the departure would cause some form of data loss (e.g. imgur uploads), and the proper solution to that is to add a "prevent this site from showing additional dialogs" button, anyway.
Anyway, I don't see anything to improve about the patch. I suspect that apps are not going to use the try_close() API and will wind up not executing the handlers even if they want to, but that's a consequence of the existing API....
(In reply to comment #4)
> I think, based on the complaints I've heard from users, we should just have
> it enabled by default.
Anyway that doesn't matter for this bug, since you are just adding try_close(); we'll decide how to use it in Epiphany.
Comment on attachment 242264 [details]
LGTM, pretty straight-forward
Committed r193826: <http://trac.webkit.org/changeset/193826>