fix: abort more descriptively for beforeunload (#49011)
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
parent
53819a8a2a
commit
aeb5af803f
5 changed files with 46 additions and 3 deletions
|
|
@ -2395,6 +2395,9 @@ void WebContents::LoadURL(const GURL& url,
|
|||
return;
|
||||
}
|
||||
|
||||
if (web_contents()->NeedToFireBeforeUnloadOrUnloadEvents())
|
||||
pending_unload_url_ = url;
|
||||
|
||||
// Discard non-committed entries to ensure we don't re-use a pending entry.
|
||||
web_contents()->GetController().DiscardNonCommittedEntries();
|
||||
web_contents()->GetController().LoadURLWithParams(params);
|
||||
|
|
@ -3897,8 +3900,15 @@ void WebContents::RunBeforeUnloadDialog(content::WebContents* web_contents,
|
|||
content::RenderFrameHost* rfh,
|
||||
bool is_reload,
|
||||
DialogClosedCallback callback) {
|
||||
// TODO: asyncify?
|
||||
bool default_prevented = Emit("will-prevent-unload");
|
||||
|
||||
if (pending_unload_url_.has_value() && !default_prevented) {
|
||||
Emit("did-fail-load", static_cast<int>(net::ERR_ABORTED),
|
||||
net::ErrorToShortString(net::ERR_ABORTED),
|
||||
pending_unload_url_.value().possibly_invalid_spec(), true);
|
||||
pending_unload_url_.reset();
|
||||
}
|
||||
|
||||
std::move(callback).Run(default_prevented, std::u16string());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -844,6 +844,8 @@ class WebContents final : public ExclusiveAccessContext,
|
|||
// that field to ensure the dtor destroys them in the right order.
|
||||
raw_ptr<WebContentsZoomController> zoom_controller_ = nullptr;
|
||||
|
||||
std::optional<GURL> pending_unload_url_ = std::nullopt;
|
||||
|
||||
// Maps url to file path, used by the file requests sent from devtools.
|
||||
typedef std::map<std::string, base::FilePath> PathsMap;
|
||||
PathsMap saved_files_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue