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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/render_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 1507
1508 void RenderFrameImpl::OnBeforeUnload() { 1508 void RenderFrameImpl::OnBeforeUnload() {
1509 TRACE_EVENT1("navigation", "RenderFrameImpl::OnBeforeUnload", 1509 TRACE_EVENT1("navigation", "RenderFrameImpl::OnBeforeUnload",
1510 "id", routing_id_); 1510 "id", routing_id_);
1511 // TODO(creis): Right now, this is only called on the main frame. Make the 1511 // TODO(creis): Right now, this is only called on the main frame. Make the
1512 // browser process send dispatchBeforeUnloadEvent to every frame that needs 1512 // browser process send dispatchBeforeUnloadEvent to every frame that needs
1513 // it. 1513 // it.
1514 CHECK(!frame_->parent()); 1514 CHECK(!frame_->parent());
1515 1515
1516 base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); 1516 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
1517 bool proceed = frame_->dispatchBeforeUnloadEvent(); 1517
1518 // TODO(clamy): Pass the right value for is_reload here.
dcheng 2016/05/03 21:34:30 Let's fix this in this CL as well: since this is s
clamy 2016/05/04 13:50:15 Done.
1519 blink::WebLocalFrame::BeforeUnloadReturnValue return_value =
1520 frame_->dispatchBeforeUnloadEvent(false);
1521 if (return_value ==
1522 blink::WebLocalFrame::BeforeUnloadReturnValue::FrameDestroyed) {
dcheng 2016/05/03 21:34:30 Let's just use weak_factory_.GetWeakPtr() to detec
clamy 2016/05/04 13:50:15 Done.
1523 // Return as the frame was destroyed by the BeforeUnload event.
1524 return;
1525 }
1526
1518 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); 1527 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
1519 Send(new FrameHostMsg_BeforeUnload_ACK(routing_id_, proceed, 1528 Send(new FrameHostMsg_BeforeUnload_ACK(
1520 before_unload_start_time, 1529 routing_id_,
1521 before_unload_end_time)); 1530 return_value == blink::WebLocalFrame::BeforeUnloadReturnValue::Proceed,
1531 before_unload_start_time, before_unload_end_time));
1522 } 1532 }
1523 1533
1524 void RenderFrameImpl::OnSwapOut( 1534 void RenderFrameImpl::OnSwapOut(
1525 int proxy_routing_id, 1535 int proxy_routing_id,
1526 bool is_loading, 1536 bool is_loading,
1527 const FrameReplicationState& replicated_frame_state) { 1537 const FrameReplicationState& replicated_frame_state) {
1528 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_); 1538 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_);
1529 RenderFrameProxy* proxy = NULL; 1539 RenderFrameProxy* proxy = NULL;
1530 1540
1531 // This codepath should only be hit for subframes when in --site-per-process. 1541 // This codepath should only be hit for subframes when in --site-per-process.
(...skipping 3313 matching lines...) Expand 10 before | Expand all | Expand 10 after
4845 // Must be a JavaScript navigation, which appears as "other". 4855 // Must be a JavaScript navigation, which appears as "other".
4846 info.navigationType == blink::WebNavigationTypeOther; 4856 info.navigationType == blink::WebNavigationTypeOther;
4847 4857
4848 if (is_fork) { 4858 if (is_fork) {
4849 // Open the URL via the browser, not via WebKit. 4859 // Open the URL via the browser, not via WebKit.
4850 OpenURL(url, Referrer(), info.defaultPolicy, 4860 OpenURL(url, Referrer(), info.defaultPolicy,
4851 info.replacesCurrentHistoryItem, false); 4861 info.replacesCurrentHistoryItem, false);
4852 return blink::WebNavigationPolicyIgnore; 4862 return blink::WebNavigationPolicyIgnore;
4853 } 4863 }
4854 4864
4865 // Execute the BeforeUnload event. If asked not to proceed or the frame is
4866 // destroyed, ignore the navigation. There is no need to execute the
4867 // BeforeUnload event during a redirect, since it was already executed at the
4868 // start of the navigation.
4869 if (!is_redirect && (!IsBrowserSideNavigationEnabled() ||
4870 info.urlRequest.checkForBrowserSideNavigation())) {
4871 // PlzNavigate: this is not executed when commiting the navigation.
4872 if (frame_->dispatchBeforeUnloadEvent(info.navigationType ==
4873 blink::WebNavigationTypeReload) !=
4874 blink::WebLocalFrame::BeforeUnloadReturnValue::Proceed) {
4875 return blink::WebNavigationPolicyIgnore;
4876 }
4877 }
4878
4855 // PlzNavigate: if the navigation is not synchronous, send it to the browser. 4879 // PlzNavigate: if the navigation is not synchronous, send it to the browser.
4856 // This includes navigations with no request being sent to the network stack. 4880 // This includes navigations with no request being sent to the network stack.
4857 if (IsBrowserSideNavigationEnabled() && 4881 if (IsBrowserSideNavigationEnabled() &&
4858 info.urlRequest.checkForBrowserSideNavigation() && 4882 info.urlRequest.checkForBrowserSideNavigation() &&
4859 ShouldMakeNetworkRequestForURL(url)) { 4883 ShouldMakeNetworkRequestForURL(url)) {
4860 BeginNavigation(&info.urlRequest, info.replacesCurrentHistoryItem, 4884 BeginNavigation(&info.urlRequest, info.replacesCurrentHistoryItem,
4861 info.isClientRedirect); 4885 info.isClientRedirect);
4862 return blink::WebNavigationPolicyHandledByClient; 4886 return blink::WebNavigationPolicyHandledByClient;
4863 } 4887 }
4864 4888
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
5596 CHECK_EQ(-1, render_view_->history_list_offset_); 5620 CHECK_EQ(-1, render_view_->history_list_offset_);
5597 CHECK_EQ(0, render_view_->history_list_length_); 5621 CHECK_EQ(0, render_view_->history_list_length_);
5598 } 5622 }
5599 } 5623 }
5600 5624
5601 void RenderFrameImpl::BeginNavigation(blink::WebURLRequest* request, 5625 void RenderFrameImpl::BeginNavigation(blink::WebURLRequest* request,
5602 bool should_replace_current_entry, 5626 bool should_replace_current_entry,
5603 bool is_client_redirect) { 5627 bool is_client_redirect) {
5604 CHECK(IsBrowserSideNavigationEnabled()); 5628 CHECK(IsBrowserSideNavigationEnabled());
5605 DCHECK(request); 5629 DCHECK(request);
5606 // TODO(clamy): Execute the beforeunload event.
5607 5630
5608 // Note: At this stage, the goal is to apply all the modifications the 5631 // Note: At this stage, the goal is to apply all the modifications the
5609 // renderer wants to make to the request, and then send it to the browser, so 5632 // renderer wants to make to the request, and then send it to the browser, so
5610 // that the actual network request can be started. Ideally, all such 5633 // that the actual network request can be started. Ideally, all such
5611 // modifications should take place in willSendRequest, and in the 5634 // modifications should take place in willSendRequest, and in the
5612 // implementation of willSendRequest for the various InspectorAgents 5635 // implementation of willSendRequest for the various InspectorAgents
5613 // (devtools). 5636 // (devtools).
5614 // 5637 //
5615 // TODO(clamy): Apply devtools override. 5638 // TODO(clamy): Apply devtools override.
5616 // TODO(clamy): Make sure that navigation requests are not modified somewhere 5639 // TODO(clamy): Make sure that navigation requests are not modified somewhere
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
6033 int match_count, 6056 int match_count,
6034 int ordinal, 6057 int ordinal,
6035 const WebRect& selection_rect, 6058 const WebRect& selection_rect,
6036 bool final_status_update) { 6059 bool final_status_update) {
6037 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, 6060 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count,
6038 selection_rect, ordinal, 6061 selection_rect, ordinal,
6039 final_status_update)); 6062 final_status_update));
6040 } 6063 }
6041 6064
6042 } // namespace content 6065 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698