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

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 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 1498
1499 ManifestManager* RenderFrameImpl::manifest_manager() { 1499 ManifestManager* RenderFrameImpl::manifest_manager() {
1500 return manifest_manager_; 1500 return manifest_manager_;
1501 } 1501 }
1502 1502
1503 void RenderFrameImpl::SetPendingNavigationParams( 1503 void RenderFrameImpl::SetPendingNavigationParams(
1504 std::unique_ptr<NavigationParams> navigation_params) { 1504 std::unique_ptr<NavigationParams> navigation_params) {
1505 pending_navigation_params_ = std::move(navigation_params); 1505 pending_navigation_params_ = std::move(navigation_params);
1506 } 1506 }
1507 1507
1508 void RenderFrameImpl::OnBeforeUnload() { 1508 void RenderFrameImpl::OnBeforeUnload(bool is_reload) {
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 // 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.
1519 // BeforeUnload event destriyed this frame.
nasko 2016/05/09 21:56:04 destroyed
clamy 2016/05/10 01:58:09 Same.
1520 base::WeakPtr<RenderFrameImpl> weak_self = weak_factory_.GetWeakPtr();
1521 bool proceed = frame_->dispatchBeforeUnloadEvent(is_reload);
1522 if (!weak_self)
1523 return;
dcheng 2016/05/04 18:41:35 It's probably slightly safer (and consistent with
clamy 2016/05/10 01:58:09 Done.
1524
1518 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); 1525 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
1519 Send(new FrameHostMsg_BeforeUnload_ACK(routing_id_, proceed, 1526 Send(new FrameHostMsg_BeforeUnload_ACK(
1520 before_unload_start_time, 1527 routing_id_, proceed, before_unload_start_time, before_unload_end_time));
1521 before_unload_end_time));
1522 } 1528 }
1523 1529
1524 void RenderFrameImpl::OnSwapOut( 1530 void RenderFrameImpl::OnSwapOut(
1525 int proxy_routing_id, 1531 int proxy_routing_id,
1526 bool is_loading, 1532 bool is_loading,
1527 const FrameReplicationState& replicated_frame_state) { 1533 const FrameReplicationState& replicated_frame_state) {
1528 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_); 1534 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_);
1529 RenderFrameProxy* proxy = NULL; 1535 RenderFrameProxy* proxy = NULL;
1530 1536
1531 // This codepath should only be hit for subframes when in --site-per-process. 1537 // 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". 4851 // Must be a JavaScript navigation, which appears as "other".
4846 info.navigationType == blink::WebNavigationTypeOther; 4852 info.navigationType == blink::WebNavigationTypeOther;
4847 4853
4848 if (is_fork) { 4854 if (is_fork) {
4849 // Open the URL via the browser, not via WebKit. 4855 // Open the URL via the browser, not via WebKit.
4850 OpenURL(url, Referrer(), info.defaultPolicy, 4856 OpenURL(url, Referrer(), info.defaultPolicy,
4851 info.replacesCurrentHistoryItem, false); 4857 info.replacesCurrentHistoryItem, false);
4852 return blink::WebNavigationPolicyIgnore; 4858 return blink::WebNavigationPolicyIgnore;
4853 } 4859 }
4854 4860
4861 // Execute the BeforeUnload event. If asked not to proceed or the frame is
4862 // destroyed, ignore the navigation. There is no need to execute the
4863 // BeforeUnload event during a redirect, since it was already executed at the
4864 // start of the navigation.
4865 // PlzNavigate: this is not executed when commiting the navigation.
4866 if (!is_redirect && (!IsBrowserSideNavigationEnabled() ||
4867 info.urlRequest.checkForBrowserSideNavigation())) {
nasko 2016/05/09 21:56:04 I'm slightly puzzled by this check. If PlzNavagait
4868 // Keep a WeakPtr to this RenderFrameHost to detect if executing the
4869 // BeforeUnload event destriyed this frame.
nasko 2016/05/09 21:56:04 This comment is a copy of the above, so fixes of t
4870 base::WeakPtr<RenderFrameImpl> weak_self = weak_factory_.GetWeakPtr();
4871
4872 if (!frame_->dispatchBeforeUnloadEvent(info.navigationType ==
4873 blink::WebNavigationTypeReload) ||
4874 !weak_self) {
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