Commit e83e16f3 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Android: run beforeunload handler when pressing system back button

Before this patch, when the history stack was empty and the user pressed
the system back button, the tab would be closed (usually --- depending
on how the tab was opened). The beforeunload handler, if any, would be
skipped, even though navigating in a different manner *would* trigger
beforeunload.

In comparison, desktop Chrome does run beforeunload when closing a tab
(via the tab close button, for example). So this discrepancy seems
unintended.

This fix *only* affects system back and not other ways of closing tabs.
So, for example, closing from the tab switcher UI will still immediately
close, but offer an undo notification bar.

This should not have any effect if a page does not have a beforeunload
handler (or the handler is not active due to the lack of a user
gesture), except that closing will be asynchronous. The same sequence
happens in TabModelImpl, as TabModel#closeTab is called with the same
arguments by way of TabWebContentsDelegateAndroid#closeContents.

Bug: 1055540
Change-Id: Ie9e45692b920db54fd3d00f06466edee01771d47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2071491
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746645}
parent e989b31d
......@@ -1793,7 +1793,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements Accessibilit
return true;
}
} else if (shouldCloseTab) {
getCurrentTabModel().closeTab(currentTab, true, false, false);
currentTab.getWebContents().dispatchBeforeUnload(false);
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment