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

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: Rebase + fixed issue with layout test Created 4 years, 6 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 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 1567
1568 ManifestManager* RenderFrameImpl::manifest_manager() { 1568 ManifestManager* RenderFrameImpl::manifest_manager() {
1569 return manifest_manager_; 1569 return manifest_manager_;
1570 } 1570 }
1571 1571
1572 void RenderFrameImpl::SetPendingNavigationParams( 1572 void RenderFrameImpl::SetPendingNavigationParams(
1573 std::unique_ptr<NavigationParams> navigation_params) { 1573 std::unique_ptr<NavigationParams> navigation_params) {
1574 pending_navigation_params_ = std::move(navigation_params); 1574 pending_navigation_params_ = std::move(navigation_params);
1575 } 1575 }
1576 1576
1577 void RenderFrameImpl::OnBeforeUnload() { 1577 void RenderFrameImpl::OnBeforeUnload(bool is_reload) {
1578 TRACE_EVENT1("navigation", "RenderFrameImpl::OnBeforeUnload", 1578 TRACE_EVENT1("navigation", "RenderFrameImpl::OnBeforeUnload",
1579 "id", routing_id_); 1579 "id", routing_id_);
1580 // TODO(creis): Right now, this is only called on the main frame. Make the 1580 // TODO(creis): Right now, this is only called on the main frame. Make the
1581 // browser process send dispatchBeforeUnloadEvent to every frame that needs 1581 // browser process send dispatchBeforeUnloadEvent to every frame that needs
1582 // it. 1582 // it.
1583 CHECK(!frame_->parent()); 1583 CHECK(!frame_->parent());
1584 1584
1585 base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); 1585 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
1586 bool proceed = frame_->dispatchBeforeUnloadEvent(); 1586 bool proceed = frame_->dispatchBeforeUnloadEvent(is_reload);
1587 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); 1587 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
1588 Send(new FrameHostMsg_BeforeUnload_ACK(routing_id_, proceed, 1588 Send(new FrameHostMsg_BeforeUnload_ACK(
1589 before_unload_start_time, 1589 routing_id_, proceed, before_unload_start_time, before_unload_end_time));
1590 before_unload_end_time));
1591 } 1590 }
1592 1591
1593 void RenderFrameImpl::OnSwapOut( 1592 void RenderFrameImpl::OnSwapOut(
1594 int proxy_routing_id, 1593 int proxy_routing_id,
1595 bool is_loading, 1594 bool is_loading,
1596 const FrameReplicationState& replicated_frame_state) { 1595 const FrameReplicationState& replicated_frame_state) {
1597 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_); 1596 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_);
1598 RenderFrameProxy* proxy = NULL; 1597 RenderFrameProxy* proxy = NULL;
1599 1598
1600 // This codepath should only be hit for subframes when in --site-per-process. 1599 // This codepath should only be hit for subframes when in --site-per-process.
(...skipping 3303 matching lines...) Expand 10 before | Expand all | Expand 10 after
4904 // Must be a JavaScript navigation, which appears as "other". 4903 // Must be a JavaScript navigation, which appears as "other".
4905 info.navigationType == blink::WebNavigationTypeOther; 4904 info.navigationType == blink::WebNavigationTypeOther;
4906 4905
4907 if (is_fork) { 4906 if (is_fork) {
4908 // Open the URL via the browser, not via WebKit. 4907 // Open the URL via the browser, not via WebKit.
4909 OpenURL(url, Referrer(), info.defaultPolicy, 4908 OpenURL(url, Referrer(), info.defaultPolicy,
4910 info.replacesCurrentHistoryItem, false); 4909 info.replacesCurrentHistoryItem, false);
4911 return blink::WebNavigationPolicyIgnore; 4910 return blink::WebNavigationPolicyIgnore;
4912 } 4911 }
4913 4912
4913 // Execute the BeforeUnload event. If asked not to proceed or the frame is
4914 // destroyed, ignore the navigation. There is no need to execute the
4915 // BeforeUnload event during a redirect, since it was already executed at the
4916 // start of the navigation.
4917 // PlzNavigate: this is not executed when commiting the navigation.
4918 if (info.defaultPolicy == blink::WebNavigationPolicyCurrentTab &&
4919 !is_redirect && (!IsBrowserSideNavigationEnabled() ||
4920 info.urlRequest.checkForBrowserSideNavigation())) {
4921 // Keep a WeakPtr to this RenderFrameHost to detect if executing the
4922 // BeforeUnload event destriyed this frame.
4923 base::WeakPtr<RenderFrameImpl> weak_self = weak_factory_.GetWeakPtr();
4924
4925 if (!frame_->dispatchBeforeUnloadEvent(info.navigationType ==
4926 blink::WebNavigationTypeReload) ||
4927 !weak_self) {
4928 return blink::WebNavigationPolicyIgnore;
4929 }
4930 }
4931
4914 // PlzNavigate: if the navigation is not synchronous, send it to the browser. 4932 // PlzNavigate: if the navigation is not synchronous, send it to the browser.
4915 // This includes navigations with no request being sent to the network stack. 4933 // This includes navigations with no request being sent to the network stack.
4916 if (IsBrowserSideNavigationEnabled() && 4934 if (IsBrowserSideNavigationEnabled() &&
4917 info.urlRequest.checkForBrowserSideNavigation() && 4935 info.urlRequest.checkForBrowserSideNavigation() &&
4918 ShouldMakeNetworkRequestForURL(url)) { 4936 ShouldMakeNetworkRequestForURL(url)) {
4919 BeginNavigation(&info.urlRequest, info.replacesCurrentHistoryItem, 4937 BeginNavigation(&info.urlRequest, info.replacesCurrentHistoryItem,
4920 info.isClientRedirect); 4938 info.isClientRedirect);
4921 return blink::WebNavigationPolicyHandledByClient; 4939 return blink::WebNavigationPolicyHandledByClient;
4922 } 4940 }
4923 4941
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
5652 CHECK_EQ(-1, render_view_->history_list_offset_); 5670 CHECK_EQ(-1, render_view_->history_list_offset_);
5653 CHECK_EQ(0, render_view_->history_list_length_); 5671 CHECK_EQ(0, render_view_->history_list_length_);
5654 } 5672 }
5655 } 5673 }
5656 5674
5657 void RenderFrameImpl::BeginNavigation(blink::WebURLRequest* request, 5675 void RenderFrameImpl::BeginNavigation(blink::WebURLRequest* request,
5658 bool should_replace_current_entry, 5676 bool should_replace_current_entry,
5659 bool is_client_redirect) { 5677 bool is_client_redirect) {
5660 CHECK(IsBrowserSideNavigationEnabled()); 5678 CHECK(IsBrowserSideNavigationEnabled());
5661 DCHECK(request); 5679 DCHECK(request);
5662 // TODO(clamy): Execute the beforeunload event.
5663 5680
5664 // Note: At this stage, the goal is to apply all the modifications the 5681 // Note: At this stage, the goal is to apply all the modifications the
5665 // renderer wants to make to the request, and then send it to the browser, so 5682 // renderer wants to make to the request, and then send it to the browser, so
5666 // that the actual network request can be started. Ideally, all such 5683 // that the actual network request can be started. Ideally, all such
5667 // modifications should take place in willSendRequest, and in the 5684 // modifications should take place in willSendRequest, and in the
5668 // implementation of willSendRequest for the various InspectorAgents 5685 // implementation of willSendRequest for the various InspectorAgents
5669 // (devtools). 5686 // (devtools).
5670 // 5687 //
5671 // TODO(clamy): Apply devtools override. 5688 // TODO(clamy): Apply devtools override.
5672 // TODO(clamy): Make sure that navigation requests are not modified somewhere 5689 // TODO(clamy): Make sure that navigation requests are not modified somewhere
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
6152 // event target. Potentially a Pepper plugin will receive the event. 6169 // event target. Potentially a Pepper plugin will receive the event.
6153 // In order to tell whether a plugin gets the last mouse event and which it 6170 // In order to tell whether a plugin gets the last mouse event and which it
6154 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6171 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6155 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6172 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6156 // |pepper_last_mouse_event_target_|. 6173 // |pepper_last_mouse_event_target_|.
6157 pepper_last_mouse_event_target_ = nullptr; 6174 pepper_last_mouse_event_target_ = nullptr;
6158 #endif 6175 #endif
6159 } 6176 }
6160 6177
6161 } // namespace content 6178 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698