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

Side by Side Diff: content/browser/frame_host/render_frame_host_impl.cc

Issue 1849343004: Remove RenderFrameHostImplState and convert it to boolean. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 4 years, 8 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/browser/frame_host/render_frame_host_impl.h" 5 #include "content/browser/frame_host/render_frame_host_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 return base::i18n::RIGHT_TO_LEFT; 129 return base::i18n::RIGHT_TO_LEFT;
130 default: 130 default:
131 NOTREACHED(); 131 NOTREACHED();
132 return base::i18n::UNKNOWN_DIRECTION; 132 return base::i18n::UNKNOWN_DIRECTION;
133 } 133 }
134 } 134 }
135 135
136 } // namespace 136 } // namespace
137 137
138 // static 138 // static
139 bool RenderFrameHostImpl::IsRFHStateActive(RenderFrameHostImplState rfh_state) {
140 return rfh_state == STATE_DEFAULT;
141 }
142
143 // static
144 RenderFrameHost* RenderFrameHost::FromID(int render_process_id, 139 RenderFrameHost* RenderFrameHost::FromID(int render_process_id,
145 int render_frame_id) { 140 int render_frame_id) {
146 return RenderFrameHostImpl::FromID(render_process_id, render_frame_id); 141 return RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
147 } 142 }
148 143
149 #if defined(OS_ANDROID) 144 #if defined(OS_ANDROID)
150 // static 145 // static
151 void RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView() { 146 void RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView() {
152 g_allow_injecting_javascript = true; 147 g_allow_injecting_javascript = true;
153 } 148 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 : render_view_host_(render_view_host), 185 : render_view_host_(render_view_host),
191 delegate_(delegate), 186 delegate_(delegate),
192 site_instance_(static_cast<SiteInstanceImpl*>(site_instance)), 187 site_instance_(static_cast<SiteInstanceImpl*>(site_instance)),
193 process_(site_instance->GetProcess()), 188 process_(site_instance->GetProcess()),
194 cross_process_frame_connector_(NULL), 189 cross_process_frame_connector_(NULL),
195 render_frame_proxy_host_(NULL), 190 render_frame_proxy_host_(NULL),
196 frame_tree_(frame_tree), 191 frame_tree_(frame_tree),
197 frame_tree_node_(frame_tree_node), 192 frame_tree_node_(frame_tree_node),
198 render_widget_host_(nullptr), 193 render_widget_host_(nullptr),
199 routing_id_(routing_id), 194 routing_id_(routing_id),
200 rfh_state_(STATE_DEFAULT), 195 is_waiting_for_swapout_ack_(false),
201 render_frame_created_(false), 196 render_frame_created_(false),
202 navigations_suspended_(false), 197 navigations_suspended_(false),
203 is_waiting_for_beforeunload_ack_(false), 198 is_waiting_for_beforeunload_ack_(false),
204 unload_ack_is_for_navigation_(false), 199 unload_ack_is_for_navigation_(false),
205 is_loading_(false), 200 is_loading_(false),
206 pending_commit_(false), 201 pending_commit_(false),
207 nav_entry_id_(0), 202 nav_entry_id_(0),
208 accessibility_reset_token_(0), 203 accessibility_reset_token_(0),
209 accessibility_reset_count_(0), 204 accessibility_reset_count_(0),
210 browser_plugin_embedder_ax_tree_id_(AXTreeIDRegistry::kNoAXTreeID), 205 browser_plugin_embedder_ax_tree_id_(AXTreeIDRegistry::kNoAXTreeID),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 255
261 GetProcess()->RemoveRoute(routing_id_); 256 GetProcess()->RemoveRoute(routing_id_);
262 g_routing_id_frame_map.Get().erase( 257 g_routing_id_frame_map.Get().erase(
263 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 258 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
264 259
265 site_instance_->RemoveObserver(this); 260 site_instance_->RemoveObserver(this);
266 261
267 if (delegate_ && render_frame_created_) 262 if (delegate_ && render_frame_created_)
268 delegate_->RenderFrameDeleted(this); 263 delegate_->RenderFrameDeleted(this);
269 264
270 bool is_active = IsRFHStateActive(rfh_state_);
271
272 // If this RenderFrameHost is swapped out, it already decremented the active 265 // If this RenderFrameHost is swapped out, it already decremented the active
273 // frame count of the SiteInstance it belongs to. 266 // frame count of the SiteInstance it belongs to.
274 if (is_active) 267 if (is_active())
275 GetSiteInstance()->DecrementActiveFrameCount(); 268 GetSiteInstance()->DecrementActiveFrameCount();
276 269
277 // If this RenderFrameHost is swapping with a RenderFrameProxyHost, the 270 // If this RenderFrameHost is swapping with a RenderFrameProxyHost, the
278 // RenderFrame will already be deleted in the renderer process. Main frame 271 // RenderFrame will already be deleted in the renderer process. Main frame
279 // RenderFrames will be cleaned up as part of deleting its RenderView. In all 272 // RenderFrames will be cleaned up as part of deleting its RenderView. In all
280 // other cases, the RenderFrame should be cleaned up (if it exists). 273 // other cases, the RenderFrame should be cleaned up (if it exists).
281 if (is_active && !frame_tree_node_->IsMainFrame() && render_frame_created_) 274 if (is_active() && !frame_tree_node_->IsMainFrame() && render_frame_created_)
282 Send(new FrameMsg_Delete(routing_id_)); 275 Send(new FrameMsg_Delete(routing_id_));
283 276
284 // NULL out the swapout timer; in crash dumps this member will be null only if 277 // NULL out the swapout timer; in crash dumps this member will be null only if
285 // the dtor has run. 278 // the dtor has run.
286 swapout_event_monitor_timeout_.reset(); 279 swapout_event_monitor_timeout_.reset();
287 280
288 for (const auto& iter: visual_state_callbacks_) { 281 for (const auto& iter: visual_state_callbacks_) {
289 iter.second.Run(false); 282 iter.second.Run(false);
290 } 283 }
291 284
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 const std::string& frame_unique_name, 830 const std::string& frame_unique_name,
838 blink::WebSandboxFlags sandbox_flags, 831 blink::WebSandboxFlags sandbox_flags,
839 const blink::WebFrameOwnerProperties& frame_owner_properties) { 832 const blink::WebFrameOwnerProperties& frame_owner_properties) {
840 // TODO(lukasza): Call ReceivedBadMessage when |frame_unique_name| is empty. 833 // TODO(lukasza): Call ReceivedBadMessage when |frame_unique_name| is empty.
841 DCHECK(!frame_unique_name.empty()); 834 DCHECK(!frame_unique_name.empty());
842 835
843 // It is possible that while a new RenderFrameHost was committed, the 836 // It is possible that while a new RenderFrameHost was committed, the
844 // RenderFrame corresponding to this host sent an IPC message to create a 837 // RenderFrame corresponding to this host sent an IPC message to create a
845 // frame and it is delivered after this host is swapped out. 838 // frame and it is delivered after this host is swapped out.
846 // Ignore such messages, as we know this RenderFrameHost is going away. 839 // Ignore such messages, as we know this RenderFrameHost is going away.
847 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT || 840 if (!is_active() || frame_tree_node_->current_frame_host() != this)
848 frame_tree_node_->current_frame_host() != this)
849 return; 841 return;
850 842
851 frame_tree_->AddFrame(frame_tree_node_, GetProcess()->GetID(), new_routing_id, 843 frame_tree_->AddFrame(frame_tree_node_, GetProcess()->GetID(), new_routing_id,
852 scope, frame_name, frame_unique_name, sandbox_flags, 844 scope, frame_name, frame_unique_name, sandbox_flags,
853 frame_owner_properties); 845 frame_owner_properties);
854 } 846 }
855 847
856 void RenderFrameHostImpl::OnDetach() { 848 void RenderFrameHostImpl::OnDetach() {
857 frame_tree_->RemoveFrame(frame_tree_node_); 849 frame_tree_->RemoveFrame(frame_tree_node_);
858 } 850 }
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 1165
1174 void RenderFrameHostImpl::SwapOut( 1166 void RenderFrameHostImpl::SwapOut(
1175 RenderFrameProxyHost* proxy, 1167 RenderFrameProxyHost* proxy,
1176 bool is_loading) { 1168 bool is_loading) {
1177 // The end of this event is in OnSwapOutACK when the RenderFrame has completed 1169 // The end of this event is in OnSwapOutACK when the RenderFrame has completed
1178 // the operation and sends back an IPC message. 1170 // the operation and sends back an IPC message.
1179 // The trace event may not end properly if the ACK times out. We expect this 1171 // The trace event may not end properly if the ACK times out. We expect this
1180 // to be fixed when RenderViewHostImpl::OnSwapOut moves to RenderFrameHost. 1172 // to be fixed when RenderViewHostImpl::OnSwapOut moves to RenderFrameHost.
1181 TRACE_EVENT_ASYNC_BEGIN0("navigation", "RenderFrameHostImpl::SwapOut", this); 1173 TRACE_EVENT_ASYNC_BEGIN0("navigation", "RenderFrameHostImpl::SwapOut", this);
1182 1174
1183 // If this RenderFrameHost is not in the default state, it must have already 1175 // If this RenderFrameHost is already pending deletion, it must have already
1184 // gone through this, therefore just return. 1176 // gone through this, therefore just return.
1185 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { 1177 if (!is_active()) {
1186 NOTREACHED() << "RFH should be in default state when calling SwapOut."; 1178 NOTREACHED() << "RFH should be in default state when calling SwapOut.";
1187 return; 1179 return;
1188 } 1180 }
1189 1181
1190 swapout_event_monitor_timeout_->Start( 1182 swapout_event_monitor_timeout_->Start(
1191 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); 1183 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS));
1192 1184
1193 // There may be no proxy if there are no active views in the process. 1185 // There may be no proxy if there are no active views in the process.
1194 int proxy_routing_id = MSG_ROUTING_NONE; 1186 int proxy_routing_id = MSG_ROUTING_NONE;
1195 FrameReplicationState replication_state; 1187 FrameReplicationState replication_state;
1196 if (proxy) { 1188 if (proxy) {
1197 set_render_frame_proxy_host(proxy); 1189 set_render_frame_proxy_host(proxy);
1198 proxy_routing_id = proxy->GetRoutingID(); 1190 proxy_routing_id = proxy->GetRoutingID();
1199 replication_state = proxy->frame_tree_node()->current_replication_state(); 1191 replication_state = proxy->frame_tree_node()->current_replication_state();
1200 } 1192 }
1201 1193
1202 if (IsRenderFrameLive()) { 1194 if (IsRenderFrameLive()) {
1203 Send(new FrameMsg_SwapOut(routing_id_, proxy_routing_id, is_loading, 1195 Send(new FrameMsg_SwapOut(routing_id_, proxy_routing_id, is_loading,
1204 replication_state)); 1196 replication_state));
1205 } 1197 }
1206 1198
1207 // If this is the last active frame in the SiteInstance, the SetState call 1199 // TODO(nasko): If the frame is not live, shouldn't we just delete the RFH by
1208 // below will trigger the deletion of the SiteInstance's proxies. 1200 // simulating the receipt of swap out ack?
Charlie Reis 2016/04/08 20:25:37 Since we know we want to this, let's rephrase into
nasko 2016/04/08 21:25:32 Done.
1209 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); 1201 is_waiting_for_swapout_ack_ = true;
1202 if (frame_tree_node_->IsMainFrame())
1203 render_view_host_->set_is_active(false);
1204
1205 // If this is the last active frame in the SiteInstance, the
1206 // DecrementActiveFrameCount call will trigger the deletion of the
1207 // SiteInstance's proxies.
1208 GetSiteInstance()->DecrementActiveFrameCount();
1210 1209
1211 if (!GetParent()) 1210 if (!GetParent())
1212 delegate_->SwappedOut(this); 1211 delegate_->SwappedOut(this);
1213 } 1212 }
1214 1213
1215 void RenderFrameHostImpl::OnBeforeUnloadACK( 1214 void RenderFrameHostImpl::OnBeforeUnloadACK(
1216 bool proceed, 1215 bool proceed,
1217 const base::TimeTicks& renderer_before_unload_start_time, 1216 const base::TimeTicks& renderer_before_unload_start_time,
1218 const base::TimeTicks& renderer_before_unload_end_time) { 1217 const base::TimeTicks& renderer_before_unload_end_time) {
1219 TRACE_EVENT_ASYNC_END1("navigation", "RenderFrameHostImpl BeforeUnload", this, 1218 TRACE_EVENT_ASYNC_END1("navigation", "RenderFrameHostImpl BeforeUnload", this,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 before_unload_end_time); 1298 before_unload_end_time);
1300 } 1299 }
1301 1300
1302 // If canceled, notify the delegate to cancel its pending navigation entry. 1301 // If canceled, notify the delegate to cancel its pending navigation entry.
1303 if (!proceed) 1302 if (!proceed)
1304 render_view_host_->GetDelegate()->DidCancelLoading(); 1303 render_view_host_->GetDelegate()->DidCancelLoading();
1305 } 1304 }
1306 1305
1307 bool RenderFrameHostImpl::IsWaitingForUnloadACK() const { 1306 bool RenderFrameHostImpl::IsWaitingForUnloadACK() const {
1308 return render_view_host_->is_waiting_for_close_ack_ || 1307 return render_view_host_->is_waiting_for_close_ack_ ||
1309 rfh_state_ == STATE_PENDING_SWAP_OUT; 1308 is_waiting_for_swapout_ack_;
1310 } 1309 }
1311 1310
1312 void RenderFrameHostImpl::OnSwapOutACK() { 1311 void RenderFrameHostImpl::OnSwapOutACK() {
1313 OnSwappedOut(); 1312 OnSwappedOut();
1314 } 1313 }
1315 1314
1316 void RenderFrameHostImpl::OnRenderProcessGone(int status, int exit_code) { 1315 void RenderFrameHostImpl::OnRenderProcessGone(int status, int exit_code) {
1317 if (frame_tree_node_->IsMainFrame()) { 1316 if (frame_tree_node_->IsMainFrame()) {
1318 // Keep the termination status so we can get at it later when we 1317 // Keep the termination status so we can get at it later when we
1319 // need to know why it died. 1318 // need to know why it died.
(...skipping 13 matching lines...) Expand all
1333 1332
1334 // Execute any pending AX tree snapshot callbacks with an empty response, 1333 // Execute any pending AX tree snapshot callbacks with an empty response,
1335 // since we're never going to get a response from this renderer. 1334 // since we're never going to get a response from this renderer.
1336 for (const auto& iter : ax_tree_snapshot_callbacks_) 1335 for (const auto& iter : ax_tree_snapshot_callbacks_)
1337 iter.second.Run(ui::AXTreeUpdate()); 1336 iter.second.Run(ui::AXTreeUpdate());
1338 ax_tree_snapshot_callbacks_.clear(); 1337 ax_tree_snapshot_callbacks_.clear();
1339 1338
1340 // If the process has died, we don't need to wait for the swap out ack from 1339 // If the process has died, we don't need to wait for the swap out ack from
1341 // this RenderFrame if it is pending deletion. Complete the swap out to 1340 // this RenderFrame if it is pending deletion. Complete the swap out to
1342 // destroy it. 1341 // destroy it.
1343 if (!IsRFHStateActive(rfh_state())) 1342 if (!is_active())
1344 OnSwappedOut(); 1343 OnSwappedOut();
1345 1344
1346 // Note: don't add any more code at this point in the function because 1345 // Note: don't add any more code at this point in the function because
1347 // |this| may be deleted. Any additional cleanup should happen before 1346 // |this| may be deleted. Any additional cleanup should happen before
1348 // the last block of code here. 1347 // the last block of code here.
1349 } 1348 }
1350 1349
1351 void RenderFrameHostImpl::OnSwappedOut() { 1350 void RenderFrameHostImpl::OnSwappedOut() {
1352 // Ignore spurious swap out ack. 1351 // Ignore spurious swap out ack.
1353 if (rfh_state_ != STATE_PENDING_SWAP_OUT) 1352 if (!is_waiting_for_swapout_ack_)
1354 return; 1353 return;
1355 1354
1356 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this); 1355 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this);
1357 swapout_event_monitor_timeout_->Stop(); 1356 swapout_event_monitor_timeout_->Stop();
1358 1357
1359 ClearAllWebUI(); 1358 ClearAllWebUI();
1360 1359
1361 // If this is a main frame RFH that's about to be deleted, update its RVH's 1360 // If this is a main frame RFH that's about to be deleted, update its RVH's
1362 // swapped-out state here, since SetState won't be called once this RFH is 1361 // swapped-out state here. https://crbug.com/505887
1363 // deleted below. https://crbug.com/505887
1364 if (frame_tree_node_->IsMainFrame()) { 1362 if (frame_tree_node_->IsMainFrame()) {
1365 render_view_host_->set_is_active(false); 1363 render_view_host_->set_is_active(false);
1366 render_view_host_->set_is_swapped_out(true); 1364 render_view_host_->set_is_swapped_out(true);
1367 } 1365 }
1368 1366
1369 bool deleted = 1367 bool deleted =
1370 frame_tree_node_->render_manager()->DeleteFromPendingList(this); 1368 frame_tree_node_->render_manager()->DeleteFromPendingList(this);
1371 CHECK(deleted); 1369 CHECK(deleted);
1372 } 1370 }
1373 1371
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 // reset but this message includes a reset token. 1628 // reset but this message includes a reset token.
1631 if (accessibility_reset_token_ != reset_token) { 1629 if (accessibility_reset_token_ != reset_token) {
1632 Send(new AccessibilityMsg_Events_ACK(routing_id_)); 1630 Send(new AccessibilityMsg_Events_ACK(routing_id_));
1633 return; 1631 return;
1634 } 1632 }
1635 accessibility_reset_token_ = 0; 1633 accessibility_reset_token_ = 0;
1636 1634
1637 RenderWidgetHostViewBase* view = GetViewForAccessibility(); 1635 RenderWidgetHostViewBase* view = GetViewForAccessibility();
1638 1636
1639 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode(); 1637 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode();
1640 if ((accessibility_mode != AccessibilityModeOff) && view && 1638 if ((accessibility_mode != AccessibilityModeOff) && view && is_active()) {
1641 RenderFrameHostImpl::IsRFHStateActive(rfh_state())) {
1642 if (accessibility_mode & AccessibilityModeFlagPlatform) 1639 if (accessibility_mode & AccessibilityModeFlagPlatform)
1643 GetOrCreateBrowserAccessibilityManager(); 1640 GetOrCreateBrowserAccessibilityManager();
1644 1641
1645 std::vector<AXEventNotificationDetails> details; 1642 std::vector<AXEventNotificationDetails> details;
1646 details.reserve(params.size()); 1643 details.reserve(params.size());
1647 for (size_t i = 0; i < params.size(); ++i) { 1644 for (size_t i = 0; i < params.size(); ++i) {
1648 const AccessibilityHostMsg_EventParams& param = params[i]; 1645 const AccessibilityHostMsg_EventParams& param = params[i];
1649 AXEventNotificationDetails detail; 1646 AXEventNotificationDetails detail;
1650 detail.event_type = param.event_type; 1647 detail.event_type = param.event_type;
1651 detail.id = param.id; 1648 detail.id = param.id;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 Send(new AccessibilityMsg_Events_ACK(routing_id_)); 1698 Send(new AccessibilityMsg_Events_ACK(routing_id_));
1702 } 1699 }
1703 1700
1704 void RenderFrameHostImpl::OnAccessibilityLocationChanges( 1701 void RenderFrameHostImpl::OnAccessibilityLocationChanges(
1705 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { 1702 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) {
1706 if (accessibility_reset_token_) 1703 if (accessibility_reset_token_)
1707 return; 1704 return;
1708 1705
1709 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 1706 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
1710 render_view_host_->GetWidget()->GetView()); 1707 render_view_host_->GetWidget()->GetView());
1711 if (view && RenderFrameHostImpl::IsRFHStateActive(rfh_state())) { 1708 if (view && is_active()) {
1712 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode(); 1709 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode();
1713 if (accessibility_mode & AccessibilityModeFlagPlatform) { 1710 if (accessibility_mode & AccessibilityModeFlagPlatform) {
1714 BrowserAccessibilityManager* manager = 1711 BrowserAccessibilityManager* manager =
1715 GetOrCreateBrowserAccessibilityManager(); 1712 GetOrCreateBrowserAccessibilityManager();
1716 if (manager) 1713 if (manager)
1717 manager->OnLocationChanges(params); 1714 manager->OnLocationChanges(params);
1718 } 1715 }
1719 // TODO(aboxhall): send location change events to web contents observers too 1716 // TODO(aboxhall): send location change events to web contents observers too
1720 } 1717 }
1721 } 1718 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 if (IsBrowserSideNavigationEnabled() && to_different_document) { 1778 if (IsBrowserSideNavigationEnabled() && to_different_document) {
1782 bad_message::ReceivedBadMessage(GetProcess(), 1779 bad_message::ReceivedBadMessage(GetProcess(),
1783 bad_message::RFH_UNEXPECTED_LOAD_START); 1780 bad_message::RFH_UNEXPECTED_LOAD_START);
1784 return; 1781 return;
1785 } 1782 }
1786 bool was_previously_loading = frame_tree_node_->frame_tree()->IsLoading(); 1783 bool was_previously_loading = frame_tree_node_->frame_tree()->IsLoading();
1787 is_loading_ = true; 1784 is_loading_ = true;
1788 1785
1789 // Only inform the FrameTreeNode of a change in load state if the load state 1786 // Only inform the FrameTreeNode of a change in load state if the load state
1790 // of this RenderFrameHost is being tracked. 1787 // of this RenderFrameHost is being tracked.
1791 if (rfh_state_ == STATE_DEFAULT) { 1788 if (is_active()) {
1792 frame_tree_node_->DidStartLoading(to_different_document, 1789 frame_tree_node_->DidStartLoading(to_different_document,
1793 was_previously_loading); 1790 was_previously_loading);
1794 } 1791 }
1795 } 1792 }
1796 1793
1797 void RenderFrameHostImpl::OnDidStopLoading() { 1794 void RenderFrameHostImpl::OnDidStopLoading() {
1798 // This method should never be called when the frame is not loading. 1795 // This method should never be called when the frame is not loading.
1799 // Unfortunately, it can happen if a history navigation happens during a 1796 // Unfortunately, it can happen if a history navigation happens during a
1800 // BeforeUnload or Unload event. 1797 // BeforeUnload or Unload event.
1801 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been 1798 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
1802 // refactored in Blink. See crbug.com/466089 1799 // refactored in Blink. See crbug.com/466089
1803 if (!is_loading_) { 1800 if (!is_loading_) {
1804 LOG(WARNING) << "OnDidStopLoading was called twice."; 1801 LOG(WARNING) << "OnDidStopLoading was called twice.";
1805 return; 1802 return;
1806 } 1803 }
1807 1804
1808 is_loading_ = false; 1805 is_loading_ = false;
1809 navigation_handle_.reset(); 1806 navigation_handle_.reset();
1810 1807
1811 // Only inform the FrameTreeNode of a change in load state if the load state 1808 // Only inform the FrameTreeNode of a change in load state if the load state
1812 // of this RenderFrameHost is being tracked. 1809 // of this RenderFrameHost is being tracked.
1813 if (rfh_state_ == STATE_DEFAULT) 1810 if (is_active())
1814 frame_tree_node_->DidStopLoading(); 1811 frame_tree_node_->DidStopLoading();
1815 } 1812 }
1816 1813
1817 void RenderFrameHostImpl::OnDidChangeLoadProgress(double load_progress) { 1814 void RenderFrameHostImpl::OnDidChangeLoadProgress(double load_progress) {
1818 frame_tree_node_->DidChangeLoadProgress(load_progress); 1815 frame_tree_node_->DidChangeLoadProgress(load_progress);
1819 } 1816 }
1820 1817
1821 void RenderFrameHostImpl::OnSerializeAsMHTMLResponse( 1818 void RenderFrameHostImpl::OnSerializeAsMHTMLResponse(
1822 int job_id, 1819 int job_id,
1823 bool success, 1820 bool success,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 1911
1915 if (browser_command_line.HasSwitch(switches::kEnableWebVR)) { 1912 if (browser_command_line.HasSwitch(switches::kEnableWebVR)) {
1916 GetServiceRegistry()->AddService(base::Bind(&VRDeviceManager::BindRequest)); 1913 GetServiceRegistry()->AddService(base::Bind(&VRDeviceManager::BindRequest));
1917 } 1914 }
1918 #endif 1915 #endif
1919 1916
1920 GetContentClient()->browser()->RegisterRenderFrameMojoServices( 1917 GetContentClient()->browser()->RegisterRenderFrameMojoServices(
1921 GetServiceRegistry(), this); 1918 GetServiceRegistry(), this);
1922 } 1919 }
1923 1920
1924 void RenderFrameHostImpl::SetState(RenderFrameHostImplState rfh_state) { 1921 void RenderFrameHostImpl::ResetWaitingState() {
Charlie Reis 2016/04/08 20:25:37 Let's put a DCHECK(is_active()) just to catch anyo
nasko 2016/04/08 21:25:32 Done.
1925 // We decrement the number of RenderFrameHosts in a SiteInstance when the
1926 // status of a RenderFrameHost gets flipped from active.
1927 if (IsRFHStateActive(rfh_state_) && !IsRFHStateActive(rfh_state))
1928 GetSiteInstance()->DecrementActiveFrameCount();
1929
1930 // The active state of the RVH is determined by its main frame, since 1922 // The active state of the RVH is determined by its main frame, since
1931 // subframes should have their own widgets. 1923 // subframes should have their own widgets.
1932 if (frame_tree_node_->IsMainFrame()) { 1924 if (frame_tree_node_->IsMainFrame()) {
1933 render_view_host_->set_is_active(IsRFHStateActive(rfh_state)); 1925 render_view_host_->set_is_active(true);
1934 render_view_host_->set_is_swapped_out(false); 1926 render_view_host_->set_is_swapped_out(false);
1935 } 1927 }
1936 1928
1937 // Whenever we change the RFH state to and from active state, we should not be 1929 // Whenever we reset the RFH state, we should not be waiting for beforeunload
1938 // waiting for beforeunload or close acks. We clear them here to be safe, 1930 // or close acks. We clear them here to be safe, since they can cause
1939 // since they can cause navigations to be ignored in 1931 // navigations to be ignored in OnDidCommitProvisionalLoad.
1940 // OnDidCommitProvisionalLoad. 1932 if (is_waiting_for_beforeunload_ack_) {
1941 // TODO(creis): Move is_waiting_for_beforeunload_ack_ into the state machine. 1933 is_waiting_for_beforeunload_ack_ = false;
1942 if (rfh_state == STATE_DEFAULT || rfh_state_ == STATE_DEFAULT) { 1934 render_view_host_->GetWidget()->decrement_in_flight_event_count();
1943 if (is_waiting_for_beforeunload_ack_) { 1935 render_view_host_->GetWidget()->StopHangMonitorTimeout();
1944 is_waiting_for_beforeunload_ack_ = false;
1945 render_view_host_->GetWidget()->decrement_in_flight_event_count();
1946 render_view_host_->GetWidget()->StopHangMonitorTimeout();
1947 }
1948 send_before_unload_start_time_ = base::TimeTicks();
1949 render_view_host_->is_waiting_for_close_ack_ = false;
1950 } 1936 }
1951 rfh_state_ = rfh_state; 1937 send_before_unload_start_time_ = base::TimeTicks();
1938 render_view_host_->is_waiting_for_close_ack_ = false;
1952 } 1939 }
1953 1940
1954 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { 1941 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) {
1955 // TODO(creis): We should also check for WebUI pages here. Also, when the 1942 // TODO(creis): We should also check for WebUI pages here. Also, when the
1956 // out-of-process iframes implementation is ready, we should check for 1943 // out-of-process iframes implementation is ready, we should check for
1957 // cross-site URLs that are not allowed to commit in this process. 1944 // cross-site URLs that are not allowed to commit in this process.
1958 1945
1959 // Give the client a chance to disallow URLs from committing. 1946 // Give the client a chance to disallow URLs from committing.
1960 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); 1947 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url);
1961 } 1948 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 1994
2008 // Only send the message if we aren't suspended at the start of a cross-site 1995 // Only send the message if we aren't suspended at the start of a cross-site
2009 // request. 1996 // request.
2010 if (navigations_suspended_) { 1997 if (navigations_suspended_) {
2011 // This may replace an existing set of params, if this is a pending RFH that 1998 // This may replace an existing set of params, if this is a pending RFH that
2012 // is navigated twice consecutively. 1999 // is navigated twice consecutively.
2013 suspended_nav_params_.reset( 2000 suspended_nav_params_.reset(
2014 new NavigationParams(common_params, start_params, request_params)); 2001 new NavigationParams(common_params, start_params, request_params));
2015 } else { 2002 } else {
2016 // Get back to a clean state, in case we start a new navigation without 2003 // Get back to a clean state, in case we start a new navigation without
2017 // completing a RFH swap or unload handler. 2004 // completing a RFH swap or unload handler.
Charlie Reis 2016/04/08 20:25:37 nit: without completing an unload handler. (I do
nasko 2016/04/08 21:25:32 Done.
2018 SetState(RenderFrameHostImpl::STATE_DEFAULT); 2005 ResetWaitingState();
2019 SendNavigateMessage(common_params, start_params, request_params); 2006 SendNavigateMessage(common_params, start_params, request_params);
2020 } 2007 }
2021 2008
2022 // Force the throbber to start. This is done because Blink's "started loading" 2009 // Force the throbber to start. This is done because Blink's "started loading"
2023 // message will be received asynchronously from the UI of the browser. But the 2010 // message will be received asynchronously from the UI of the browser. But the
2024 // throbber needs to be kept in sync with what's happening in the UI. For 2011 // throbber needs to be kept in sync with what's happening in the UI. For
2025 // example, the throbber will start immediately when the user navigates even 2012 // example, the throbber will start immediately when the user navigates even
2026 // if the renderer is delayed. There is also an issue with the throbber 2013 // if the renderer is delayed. There is also an issue with the throbber
2027 // starting because the WebUI (which controls whether the favicon is 2014 // starting because the WebUI (which controls whether the favicon is
2028 // displayed) happens synchronously. If the start loading messages was 2015 // displayed) happens synchronously. If the start loading messages was
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 scoped_ptr<StreamHandle> body, 2161 scoped_ptr<StreamHandle> body,
2175 const CommonNavigationParams& common_params, 2162 const CommonNavigationParams& common_params,
2176 const RequestNavigationParams& request_params, 2163 const RequestNavigationParams& request_params,
2177 bool is_view_source) { 2164 bool is_view_source) {
2178 DCHECK((response && body.get()) || 2165 DCHECK((response && body.get()) ||
2179 !ShouldMakeNetworkRequestForURL(common_params.url)); 2166 !ShouldMakeNetworkRequestForURL(common_params.url));
2180 UpdatePermissionsForNavigation(common_params, request_params); 2167 UpdatePermissionsForNavigation(common_params, request_params);
2181 2168
2182 // Get back to a clean state, in case we start a new navigation without 2169 // Get back to a clean state, in case we start a new navigation without
2183 // completing a RFH swap or unload handler. 2170 // completing a RFH swap or unload handler.
2184 SetState(RenderFrameHostImpl::STATE_DEFAULT); 2171 ResetWaitingState();
2185 2172
2186 // The renderer can exit view source mode when any error or cancellation 2173 // The renderer can exit view source mode when any error or cancellation
2187 // happen. When reusing the same renderer, overwrite to recover the mode. 2174 // happen. When reusing the same renderer, overwrite to recover the mode.
2188 if (is_view_source && 2175 if (is_view_source &&
2189 this == frame_tree_node_->render_manager()->current_frame_host()) { 2176 this == frame_tree_node_->render_manager()->current_frame_host()) {
2190 DCHECK(!GetParent()); 2177 DCHECK(!GetParent());
2191 render_view_host()->Send(new FrameMsg_EnableViewSourceMode(routing_id_)); 2178 render_view_host()->Send(new FrameMsg_EnableViewSourceMode(routing_id_));
2192 } 2179 }
2193 2180
2194 const GURL body_url = body.get() ? body->GetURL() : GURL(); 2181 const GURL body_url = body.get() ? body->GetURL() : GURL();
(...skipping 20 matching lines...) Expand all
2215 } 2202 }
2216 } 2203 }
2217 2204
2218 void RenderFrameHostImpl::FailedNavigation( 2205 void RenderFrameHostImpl::FailedNavigation(
2219 const CommonNavigationParams& common_params, 2206 const CommonNavigationParams& common_params,
2220 const RequestNavigationParams& request_params, 2207 const RequestNavigationParams& request_params,
2221 bool has_stale_copy_in_cache, 2208 bool has_stale_copy_in_cache,
2222 int error_code) { 2209 int error_code) {
2223 // Get back to a clean state, in case a new navigation started without 2210 // Get back to a clean state, in case a new navigation started without
2224 // completing a RFH swap or unload handler. 2211 // completing a RFH swap or unload handler.
2225 SetState(RenderFrameHostImpl::STATE_DEFAULT); 2212 ResetWaitingState();
2226 2213
2227 Send(new FrameMsg_FailedNavigation(routing_id_, common_params, request_params, 2214 Send(new FrameMsg_FailedNavigation(routing_id_, common_params, request_params,
2228 has_stale_copy_in_cache, error_code)); 2215 has_stale_copy_in_cache, error_code));
2229 2216
2230 // An error page is expected to commit, hence why is_loading_ is set to true. 2217 // An error page is expected to commit, hence why is_loading_ is set to true.
2231 is_loading_ = true; 2218 is_loading_ = true;
2232 frame_tree_node_->ResetNavigationRequest(true); 2219 frame_tree_node_->ResetNavigationRequest(true);
2233 } 2220 }
2234 2221
2235 void RenderFrameHostImpl::SetUpMojoIfNeeded() { 2222 void RenderFrameHostImpl::SetUpMojoIfNeeded() {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 mojo::GetProxy(&mojo_image_downloader_)); 2369 mojo::GetProxy(&mojo_image_downloader_));
2383 } 2370 }
2384 return mojo_image_downloader_; 2371 return mojo_image_downloader_;
2385 } 2372 }
2386 2373
2387 void RenderFrameHostImpl::ResetLoadingState() { 2374 void RenderFrameHostImpl::ResetLoadingState() {
2388 if (is_loading()) { 2375 if (is_loading()) {
2389 // When pending deletion, just set the loading state to not loading. 2376 // When pending deletion, just set the loading state to not loading.
2390 // Otherwise, OnDidStopLoading will take care of that, as well as sending 2377 // Otherwise, OnDidStopLoading will take care of that, as well as sending
2391 // notification to the FrameTreeNode about the change in loading state. 2378 // notification to the FrameTreeNode about the change in loading state.
2392 if (rfh_state_ != STATE_DEFAULT) 2379 if (!is_active())
2393 is_loading_ = false; 2380 is_loading_ = false;
2394 else 2381 else
2395 OnDidStopLoading(); 2382 OnDidStopLoading();
2396 } 2383 }
2397 } 2384 }
2398 2385
2399 bool RenderFrameHostImpl::IsSameSiteInstance( 2386 bool RenderFrameHostImpl::IsSameSiteInstance(
2400 RenderFrameHostImpl* other_render_frame_host) { 2387 RenderFrameHostImpl* other_render_frame_host) {
2401 // As a sanity check, make sure the frame belongs to the same BrowserContext. 2388 // As a sanity check, make sure the frame belongs to the same BrowserContext.
2402 CHECK_EQ(GetSiteInstance()->GetBrowserContext(), 2389 CHECK_EQ(GetSiteInstance()->GetBrowserContext(),
(...skipping 14 matching lines...) Expand all
2417 } 2404 }
2418 2405
2419 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting( 2406 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting(
2420 const base::Callback<void(RenderFrameHostImpl*, ui::AXEvent, int)>& 2407 const base::Callback<void(RenderFrameHostImpl*, ui::AXEvent, int)>&
2421 callback) { 2408 callback) {
2422 accessibility_testing_callback_ = callback; 2409 accessibility_testing_callback_ = callback;
2423 } 2410 }
2424 2411
2425 void RenderFrameHostImpl::UpdateAXTreeData() { 2412 void RenderFrameHostImpl::UpdateAXTreeData() {
2426 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode(); 2413 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode();
2427 if (accessibility_mode == AccessibilityModeOff || 2414 if (accessibility_mode == AccessibilityModeOff || !is_active()) {
2428 !RenderFrameHostImpl::IsRFHStateActive(rfh_state())) {
2429 return; 2415 return;
2430 } 2416 }
2431 2417
2432 std::vector<AXEventNotificationDetails> details; 2418 std::vector<AXEventNotificationDetails> details;
2433 details.reserve(1U); 2419 details.reserve(1U);
2434 AXEventNotificationDetails detail; 2420 AXEventNotificationDetails detail;
2435 detail.ax_tree_id = GetAXTreeID(); 2421 detail.ax_tree_id = GetAXTreeID();
2436 detail.update.has_tree_data = true; 2422 detail.update.has_tree_data = true;
2437 AXContentTreeDataToAXTreeData(&detail.update.tree_data); 2423 AXContentTreeDataToAXTreeData(&detail.update.tree_data);
2438 details.push_back(detail); 2424 details.push_back(detail);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2549 if (navigations_suspended_) { 2535 if (navigations_suspended_) {
2550 TRACE_EVENT_ASYNC_BEGIN0("navigation", 2536 TRACE_EVENT_ASYNC_BEGIN0("navigation",
2551 "RenderFrameHostImpl navigation suspended", this); 2537 "RenderFrameHostImpl navigation suspended", this);
2552 } else { 2538 } else {
2553 TRACE_EVENT_ASYNC_END0("navigation", 2539 TRACE_EVENT_ASYNC_END0("navigation",
2554 "RenderFrameHostImpl navigation suspended", this); 2540 "RenderFrameHostImpl navigation suspended", this);
2555 } 2541 }
2556 2542
2557 if (!suspend && suspended_nav_params_) { 2543 if (!suspend && suspended_nav_params_) {
2558 // There's navigation message params waiting to be sent. Now that we're not 2544 // There's navigation message params waiting to be sent. Now that we're not
2559 // suspended anymore, resume navigation by sending them. If we were swapped 2545 // suspended anymore, resume navigation by sending them.
2560 // out, we should also stop filtering out the IPC messages now. 2546 ResetWaitingState();
2561 SetState(RenderFrameHostImpl::STATE_DEFAULT);
2562 2547
2563 DCHECK(!proceed_time.is_null()); 2548 DCHECK(!proceed_time.is_null());
2564 // TODO(csharrison): Make sure that PlzNavigate and the current architecture 2549 // TODO(csharrison): Make sure that PlzNavigate and the current architecture
2565 // measure navigation start in the same way in the presence of the 2550 // measure navigation start in the same way in the presence of the
2566 // BeforeUnload event. 2551 // BeforeUnload event.
2567 suspended_nav_params_->common_params.navigation_start = proceed_time; 2552 suspended_nav_params_->common_params.navigation_start = proceed_time;
2568 SendNavigateMessage(suspended_nav_params_->common_params, 2553 SendNavigateMessage(suspended_nav_params_->common_params,
2569 suspended_nav_params_->start_params, 2554 suspended_nav_params_->start_params,
2570 suspended_nav_params_->request_params); 2555 suspended_nav_params_->request_params);
2571 suspended_nav_params_.reset(); 2556 suspended_nav_params_.reset();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 } 2728 }
2744 2729
2745 void RenderFrameHostImpl::CreateWebBluetoothService( 2730 void RenderFrameHostImpl::CreateWebBluetoothService(
2746 blink::mojom::WebBluetoothServiceRequest request) { 2731 blink::mojom::WebBluetoothServiceRequest request) {
2747 DCHECK(!web_bluetooth_service_); 2732 DCHECK(!web_bluetooth_service_);
2748 web_bluetooth_service_.reset( 2733 web_bluetooth_service_.reset(
2749 new WebBluetoothServiceImpl(this, std::move(request))); 2734 new WebBluetoothServiceImpl(this, std::move(request)));
2750 } 2735 }
2751 2736
2752 } // namespace content 2737 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698