Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1473)

Unified Diff: content/renderer/render_frame_impl.cc

Issue 1890493002: PlzNavigate: properly execute BeforeUnload on renderer initiated navigations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed dcheng's comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/render_frame_impl.cc
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index f6990c9423a5cfc00eba249c022d6da6348aa73e..8423f9dcafb17c449b03d02a90f602ee0df40f12 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -1505,7 +1505,7 @@ void RenderFrameImpl::SetPendingNavigationParams(
pending_navigation_params_ = std::move(navigation_params);
}
-void RenderFrameImpl::OnBeforeUnload() {
+void RenderFrameImpl::OnBeforeUnload(bool is_reload) {
TRACE_EVENT1("navigation", "RenderFrameImpl::OnBeforeUnload",
"id", routing_id_);
// TODO(creis): Right now, this is only called on the main frame. Make the
@@ -1514,11 +1514,17 @@ void RenderFrameImpl::OnBeforeUnload() {
CHECK(!frame_->parent());
base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
- bool proceed = frame_->dispatchBeforeUnloadEvent();
+
+ // Keep a WeakPtr to this RenderFrameHost to detect if executing the
nasko 2016/05/09 21:56:04 RenderFrame. The RFH is browser side.
clamy 2016/05/10 01:58:09 Removed this part as per dcheng's comment.
+ // BeforeUnload event destriyed this frame.
nasko 2016/05/09 21:56:04 destroyed
clamy 2016/05/10 01:58:09 Same.
+ base::WeakPtr<RenderFrameImpl> weak_self = weak_factory_.GetWeakPtr();
+ bool proceed = frame_->dispatchBeforeUnloadEvent(is_reload);
+ if (!weak_self)
+ return;
dcheng 2016/05/04 18:41:35 It's probably slightly safer (and consistent with
clamy 2016/05/10 01:58:09 Done.
+
base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
- Send(new FrameHostMsg_BeforeUnload_ACK(routing_id_, proceed,
- before_unload_start_time,
- before_unload_end_time));
+ Send(new FrameHostMsg_BeforeUnload_ACK(
+ routing_id_, proceed, before_unload_start_time, before_unload_end_time));
}
void RenderFrameImpl::OnSwapOut(
@@ -4852,6 +4858,24 @@ WebNavigationPolicy RenderFrameImpl::decidePolicyForNavigation(
return blink::WebNavigationPolicyIgnore;
}
+ // Execute the BeforeUnload event. If asked not to proceed or the frame is
+ // destroyed, ignore the navigation. There is no need to execute the
+ // BeforeUnload event during a redirect, since it was already executed at the
+ // start of the navigation.
+ // PlzNavigate: this is not executed when commiting the navigation.
+ if (!is_redirect && (!IsBrowserSideNavigationEnabled() ||
+ info.urlRequest.checkForBrowserSideNavigation())) {
nasko 2016/05/09 21:56:04 I'm slightly puzzled by this check. If PlzNavagait
+ // Keep a WeakPtr to this RenderFrameHost to detect if executing the
+ // BeforeUnload event destriyed this frame.
nasko 2016/05/09 21:56:04 This comment is a copy of the above, so fixes of t
+ base::WeakPtr<RenderFrameImpl> weak_self = weak_factory_.GetWeakPtr();
+
+ if (!frame_->dispatchBeforeUnloadEvent(info.navigationType ==
+ blink::WebNavigationTypeReload) ||
+ !weak_self) {
+ return blink::WebNavigationPolicyIgnore;
+ }
+ }
+
// PlzNavigate: if the navigation is not synchronous, send it to the browser.
// This includes navigations with no request being sent to the network stack.
if (IsBrowserSideNavigationEnabled() &&
@@ -5603,7 +5627,6 @@ void RenderFrameImpl::BeginNavigation(blink::WebURLRequest* request,
bool is_client_redirect) {
CHECK(IsBrowserSideNavigationEnabled());
DCHECK(request);
- // TODO(clamy): Execute the beforeunload event.
// Note: At this stage, the goal is to apply all the modifications the
// renderer wants to make to the request, and then send it to the browser, so

Powered by Google App Engine
This is Rietveld 408576698