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

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 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 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 1494
1495 ManifestManager* RenderFrameImpl::manifest_manager() { 1495 ManifestManager* RenderFrameImpl::manifest_manager() {
1496 return manifest_manager_; 1496 return manifest_manager_;
1497 } 1497 }
1498 1498
1499 void RenderFrameImpl::SetPendingNavigationParams( 1499 void RenderFrameImpl::SetPendingNavigationParams(
1500 std::unique_ptr<NavigationParams> navigation_params) { 1500 std::unique_ptr<NavigationParams> navigation_params) {
1501 pending_navigation_params_ = std::move(navigation_params); 1501 pending_navigation_params_ = std::move(navigation_params);
1502 } 1502 }
1503 1503
1504 void RenderFrameImpl::OnBeforeUnload() { 1504 void RenderFrameImpl::OnBeforeUnload(bool is_reload) {
1505 TRACE_EVENT1("navigation", "RenderFrameImpl::OnBeforeUnload", 1505 TRACE_EVENT1("navigation", "RenderFrameImpl::OnBeforeUnload",
1506 "id", routing_id_); 1506 "id", routing_id_);
1507 // TODO(creis): Right now, this is only called on the main frame. Make the 1507 // TODO(creis): Right now, this is only called on the main frame. Make the
1508 // browser process send dispatchBeforeUnloadEvent to every frame that needs 1508 // browser process send dispatchBeforeUnloadEvent to every frame that needs
1509 // it. 1509 // it.
1510 CHECK(!frame_->parent()); 1510 CHECK(!frame_->parent());
1511 1511
1512 base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); 1512 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
1513 bool proceed = frame_->dispatchBeforeUnloadEvent(); 1513 bool proceed = frame_->dispatchBeforeUnloadEvent(is_reload);
1514 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); 1514 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
1515 Send(new FrameHostMsg_BeforeUnload_ACK(routing_id_, proceed, 1515 Send(new FrameHostMsg_BeforeUnload_ACK(
1516 before_unload_start_time, 1516 routing_id_, proceed, before_unload_start_time, before_unload_end_time));
1517 before_unload_end_time));
1518 } 1517 }
1519 1518
1520 void RenderFrameImpl::OnSwapOut( 1519 void RenderFrameImpl::OnSwapOut(
1521 int proxy_routing_id, 1520 int proxy_routing_id,
1522 bool is_loading, 1521 bool is_loading,
1523 const FrameReplicationState& replicated_frame_state) { 1522 const FrameReplicationState& replicated_frame_state) {
1524 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_); 1523 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_);
1525 RenderFrameProxy* proxy = NULL; 1524 RenderFrameProxy* proxy = NULL;
1526 1525
1527 // This codepath should only be hit for subframes when in --site-per-process. 1526 // This codepath should only be hit for subframes when in --site-per-process.
(...skipping 3304 matching lines...) Expand 10 before | Expand all | Expand 10 after
4832 // Must be a JavaScript navigation, which appears as "other". 4831 // Must be a JavaScript navigation, which appears as "other".
4833 info.navigationType == blink::WebNavigationTypeOther; 4832 info.navigationType == blink::WebNavigationTypeOther;
4834 4833
4835 if (is_fork) { 4834 if (is_fork) {
4836 // Open the URL via the browser, not via WebKit. 4835 // Open the URL via the browser, not via WebKit.
4837 OpenURL(url, Referrer(), info.defaultPolicy, 4836 OpenURL(url, Referrer(), info.defaultPolicy,
4838 info.replacesCurrentHistoryItem, false); 4837 info.replacesCurrentHistoryItem, false);
4839 return blink::WebNavigationPolicyIgnore; 4838 return blink::WebNavigationPolicyIgnore;
4840 } 4839 }
4841 4840
4841 // Execute the BeforeUnload event. If asked not to proceed or the frame is
4842 // destroyed, ignore the navigation. There is no need to execute the
4843 // BeforeUnload event during a redirect, since it was already executed at the
4844 // start of the navigation.
4845 // PlzNavigate: this is not executed when commiting the navigation.
4846 if (!is_redirect && (!IsBrowserSideNavigationEnabled() ||
4847 info.urlRequest.checkForBrowserSideNavigation())) {
4848 // Keep a WeakPtr to this RenderFrameHost to detect if executing the
4849 // BeforeUnload event destriyed this frame.
4850 base::WeakPtr<RenderFrameImpl> weak_self = weak_factory_.GetWeakPtr();
4851
4852 if (!frame_->dispatchBeforeUnloadEvent(info.navigationType ==
4853 blink::WebNavigationTypeReload) ||
4854 !weak_self) {
4855 return blink::WebNavigationPolicyIgnore;
4856 }
4857 }
4858
4842 // PlzNavigate: if the navigation is not synchronous, send it to the browser. 4859 // PlzNavigate: if the navigation is not synchronous, send it to the browser.
4843 // This includes navigations with no request being sent to the network stack. 4860 // This includes navigations with no request being sent to the network stack.
4844 if (IsBrowserSideNavigationEnabled() && 4861 if (IsBrowserSideNavigationEnabled() &&
4845 info.urlRequest.checkForBrowserSideNavigation() && 4862 info.urlRequest.checkForBrowserSideNavigation() &&
4846 ShouldMakeNetworkRequestForURL(url)) { 4863 ShouldMakeNetworkRequestForURL(url)) {
4847 BeginNavigation(&info.urlRequest, info.replacesCurrentHistoryItem, 4864 BeginNavigation(&info.urlRequest, info.replacesCurrentHistoryItem,
4848 info.isClientRedirect); 4865 info.isClientRedirect);
4849 return blink::WebNavigationPolicyHandledByClient; 4866 return blink::WebNavigationPolicyHandledByClient;
4850 } 4867 }
4851 4868
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
5583 CHECK_EQ(-1, render_view_->history_list_offset_); 5600 CHECK_EQ(-1, render_view_->history_list_offset_);
5584 CHECK_EQ(0, render_view_->history_list_length_); 5601 CHECK_EQ(0, render_view_->history_list_length_);
5585 } 5602 }
5586 } 5603 }
5587 5604
5588 void RenderFrameImpl::BeginNavigation(blink::WebURLRequest* request, 5605 void RenderFrameImpl::BeginNavigation(blink::WebURLRequest* request,
5589 bool should_replace_current_entry, 5606 bool should_replace_current_entry,
5590 bool is_client_redirect) { 5607 bool is_client_redirect) {
5591 CHECK(IsBrowserSideNavigationEnabled()); 5608 CHECK(IsBrowserSideNavigationEnabled());
5592 DCHECK(request); 5609 DCHECK(request);
5593 // TODO(clamy): Execute the beforeunload event.
5594 5610
5595 // Note: At this stage, the goal is to apply all the modifications the 5611 // Note: At this stage, the goal is to apply all the modifications the
5596 // renderer wants to make to the request, and then send it to the browser, so 5612 // renderer wants to make to the request, and then send it to the browser, so
5597 // that the actual network request can be started. Ideally, all such 5613 // that the actual network request can be started. Ideally, all such
5598 // modifications should take place in willSendRequest, and in the 5614 // modifications should take place in willSendRequest, and in the
5599 // implementation of willSendRequest for the various InspectorAgents 5615 // implementation of willSendRequest for the various InspectorAgents
5600 // (devtools). 5616 // (devtools).
5601 // 5617 //
5602 // TODO(clamy): Apply devtools override. 5618 // TODO(clamy): Apply devtools override.
5603 // TODO(clamy): Make sure that navigation requests are not modified somewhere 5619 // TODO(clamy): Make sure that navigation requests are not modified somewhere
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
6020 int match_count, 6036 int match_count,
6021 int ordinal, 6037 int ordinal,
6022 const WebRect& selection_rect, 6038 const WebRect& selection_rect,
6023 bool final_status_update) { 6039 bool final_status_update) {
6024 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, 6040 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count,
6025 selection_rect, ordinal, 6041 selection_rect, ordinal,
6026 final_status_update)); 6042 final_status_update));
6027 } 6043 }
6028 6044
6029 } // namespace content 6045 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698