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

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

Issue 1545973002: Remove the is_loading_ field from WebContentsImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed issue with swapped-out RFHs Created 4 years, 11 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/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 pending_web_ui_type_(WebUI::kNoWebUI), 206 pending_web_ui_type_(WebUI::kNoWebUI),
207 should_reuse_web_ui_(false), 207 should_reuse_web_ui_(false),
208 weak_ptr_factory_(this) { 208 weak_ptr_factory_(this) {
209 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 209 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
210 bool hidden = !!(flags & CREATE_RF_HIDDEN); 210 bool hidden = !!(flags & CREATE_RF_HIDDEN);
211 frame_tree_->AddRenderViewHostRef(render_view_host_); 211 frame_tree_->AddRenderViewHostRef(render_view_host_);
212 GetProcess()->AddRoute(routing_id_, this); 212 GetProcess()->AddRoute(routing_id_, this);
213 g_routing_id_frame_map.Get().insert(std::make_pair( 213 g_routing_id_frame_map.Get().insert(std::make_pair(
214 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 214 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
215 this)); 215 this));
216 site_instance_->AddObserver(this);
216 217
217 if (is_swapped_out) { 218 if (is_swapped_out) {
218 rfh_state_ = STATE_SWAPPED_OUT; 219 rfh_state_ = STATE_SWAPPED_OUT;
219 } else { 220 } else {
220 rfh_state_ = STATE_DEFAULT; 221 rfh_state_ = STATE_DEFAULT;
221 GetSiteInstance()->IncrementActiveFrameCount(); 222 GetSiteInstance()->IncrementActiveFrameCount();
222 } 223 }
223 224
224 // New child frames should inherit the nav_entry_id of their parent. 225 // New child frames should inherit the nav_entry_id of their parent.
225 if (frame_tree_node_->parent()) { 226 if (frame_tree_node_->parent()) {
(...skipping 25 matching lines...) Expand all
251 252
252 RenderFrameHostImpl::~RenderFrameHostImpl() { 253 RenderFrameHostImpl::~RenderFrameHostImpl() {
253 // Release the WebUI instances before all else as the WebUI may accesses the 254 // Release the WebUI instances before all else as the WebUI may accesses the
254 // RenderFrameHost during cleanup. 255 // RenderFrameHost during cleanup.
255 ClearAllWebUI(); 256 ClearAllWebUI();
256 257
257 GetProcess()->RemoveRoute(routing_id_); 258 GetProcess()->RemoveRoute(routing_id_);
258 g_routing_id_frame_map.Get().erase( 259 g_routing_id_frame_map.Get().erase(
259 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 260 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
260 261
262 site_instance_->RemoveObserver(this);
263
261 if (delegate_ && render_frame_created_) 264 if (delegate_ && render_frame_created_)
262 delegate_->RenderFrameDeleted(this); 265 delegate_->RenderFrameDeleted(this);
263 266
264 bool is_active = IsRFHStateActive(rfh_state_); 267 bool is_active = IsRFHStateActive(rfh_state_);
265 268
266 // If this RenderFrameHost is swapped out, it already decremented the active 269 // If this RenderFrameHost is swapped out, it already decremented the active
267 // frame count of the SiteInstance it belongs to. 270 // frame count of the SiteInstance it belongs to.
268 if (is_active) 271 if (is_active)
269 GetSiteInstance()->DecrementActiveFrameCount(); 272 GetSiteInstance()->DecrementActiveFrameCount();
270 273
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach) 509 IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach)
507 IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused, OnFrameFocused) 510 IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused, OnFrameFocused)
508 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoad, 511 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoad,
509 OnDidStartProvisionalLoad) 512 OnDidStartProvisionalLoad)
510 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError, 513 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError,
511 OnDidFailProvisionalLoadWithError) 514 OnDidFailProvisionalLoadWithError)
512 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError, 515 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError,
513 OnDidFailLoadWithError) 516 OnDidFailLoadWithError)
514 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad, 517 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad,
515 OnDidCommitProvisionalLoad(msg)) 518 OnDidCommitProvisionalLoad(msg))
516 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDropNavigation, OnDidDropNavigation)
517 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateState, OnUpdateState) 519 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateState, OnUpdateState)
518 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL) 520 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL)
519 IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted, 521 IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted,
520 OnDocumentOnLoadCompleted) 522 OnDocumentOnLoadCompleted)
521 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK) 523 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK)
522 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK) 524 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK)
523 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu) 525 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu)
524 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse, 526 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse,
525 OnJavaScriptExecuteResponse) 527 OnJavaScriptExecuteResponse)
526 IPC_MESSAGE_HANDLER(FrameHostMsg_VisualStateResponse, 528 IPC_MESSAGE_HANDLER(FrameHostMsg_VisualStateResponse,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 681
680 gfx::NativeViewAccessible 682 gfx::NativeViewAccessible
681 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() { 683 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() {
682 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 684 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
683 render_view_host_->GetWidget()->GetView()); 685 render_view_host_->GetWidget()->GetView());
684 if (view) 686 if (view)
685 return view->AccessibilityGetNativeViewAccessible(); 687 return view->AccessibilityGetNativeViewAccessible();
686 return NULL; 688 return NULL;
687 } 689 }
688 690
691 void RenderFrameHostImpl::ActiveFrameCountIsZero(
692 SiteInstanceImpl* site_instance) {}
693
694 void RenderFrameHostImpl::RenderProcessGone(SiteInstanceImpl* site_instance) {
ncarter (slow) 2016/01/21 00:26:40 I'm glad you've done this. I also have envisioned
695 DCHECK(site_instance == site_instance_.get());
696
697 // The render process is gone, this frame can no longer be loading.
698 ResetLoadingState();
nasko 2016/01/20 20:58:34 Let's not add implementation of SiteInstanceImpl::
ncarter (slow) 2016/01/21 00:26:40 I'm not sure I agree with nasko. I think it's more
clamy 2016/01/22 13:08:15 I initially tried to make things work in RFHM::Ren
nasko 2016/01/22 17:52:59 I would prefer not to have the empty method here.
clamy 2016/01/25 14:01:18 I made it non pure virtual in SiteInstanceImpl::Ob
699 }
700
689 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id, 701 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id,
690 int opener_routing_id, 702 int opener_routing_id,
691 int parent_routing_id, 703 int parent_routing_id,
692 int previous_sibling_routing_id) { 704 int previous_sibling_routing_id) {
693 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame"); 705 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame");
694 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; 706 DCHECK(!IsRenderFrameLive()) << "Creating frame twice";
695 707
696 // The process may (if we're sharing a process with another host that already 708 // The process may (if we're sharing a process with another host that already
697 // initialized it) or may not (we have our own process or the old process 709 // initialized it) or may not (we have our own process or the old process
698 // crashed) have been initialized. Calling Init multiple times will be 710 // crashed) have been initialized. Calling Init multiple times will be
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 !validated_params.was_within_same_page) { 1042 !validated_params.was_within_same_page) {
1031 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost()) 1043 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost())
1032 ->StartNewContentRenderingTimeout(); 1044 ->StartNewContentRenderingTimeout();
1033 } 1045 }
1034 1046
1035 // PlzNavigate 1047 // PlzNavigate
1036 if (IsBrowserSideNavigationEnabled()) 1048 if (IsBrowserSideNavigationEnabled())
1037 pending_commit_ = false; 1049 pending_commit_ = false;
1038 } 1050 }
1039 1051
1040 void RenderFrameHostImpl::OnDidDropNavigation() {
1041 // At the end of Navigate(), the FrameTreeNode's DidStartLoading is called to
1042 // force the spinner to start, even if the renderer didn't yet begin the load.
1043 // If it turns out that the renderer dropped the navigation, the spinner needs
1044 // to be turned off.
1045 frame_tree_node_->DidStopLoading();
1046 navigation_handle_.reset();
1047 }
1048
1049 void RenderFrameHostImpl::OnUpdateState(const PageState& state) { 1052 void RenderFrameHostImpl::OnUpdateState(const PageState& state) {
1050 // TODO(creis): Verify the state's ISN matches the last committed FNE. 1053 // TODO(creis): Verify the state's ISN matches the last committed FNE.
1051 1054
1052 // Without this check, the renderer can trick the browser into using 1055 // Without this check, the renderer can trick the browser into using
1053 // filenames it can't access in a future session restore. 1056 // filenames it can't access in a future session restore.
1054 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl. 1057 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl.
1055 if (!render_view_host_->CanAccessFilesOfPageState(state)) { 1058 if (!render_view_host_->CanAccessFilesOfPageState(state)) {
1056 bad_message::ReceivedBadMessage( 1059 bad_message::ReceivedBadMessage(
1057 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE); 1060 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE);
1058 return; 1061 return;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { 1303 frame_tree_node_->render_manager()->IsPendingDeletion(this)) {
1301 render_view_host_->set_is_active(false); 1304 render_view_host_->set_is_active(false);
1302 render_view_host_->set_is_swapped_out(true); 1305 render_view_host_->set_is_swapped_out(true);
1303 } 1306 }
1304 1307
1305 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) { 1308 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) {
1306 // We are now deleted. 1309 // We are now deleted.
1307 return; 1310 return;
1308 } 1311 }
1309 1312
1313 ResetLoadingState();
1314
1310 // If this RFH wasn't pending deletion, then it is now swapped out. 1315 // If this RFH wasn't pending deletion, then it is now swapped out.
1311 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT); 1316 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT);
1312 } 1317 }
1313 1318
1314 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { 1319 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) {
1315 // Validate the URLs in |params|. If the renderer can't request the URLs 1320 // Validate the URLs in |params|. If the renderer can't request the URLs
1316 // directly, don't show them in the context menu. 1321 // directly, don't show them in the context menu.
1317 ContextMenuParams validated_params(params); 1322 ContextMenuParams validated_params(params);
1318 RenderProcessHost* process = GetProcess(); 1323 RenderProcessHost* process = GetProcess();
1319 1324
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin()); 1690 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin());
1686 else 1691 else
1687 delegate_->ExitFullscreenMode(); 1692 delegate_->ExitFullscreenMode();
1688 1693
1689 // The previous call might change the fullscreen state. We need to make sure 1694 // The previous call might change the fullscreen state. We need to make sure
1690 // the renderer is aware of that, which is done via the resize message. 1695 // the renderer is aware of that, which is done via the resize message.
1691 render_view_host_->GetWidget()->WasResized(); 1696 render_view_host_->GetWidget()->WasResized();
1692 } 1697 }
1693 1698
1694 void RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) { 1699 void RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) {
1695 // Any main frame load to a new document should reset the load since it will
1696 // replace the current page and any frames.
1697 if (to_different_document && !GetParent())
1698 is_loading_ = false;
1699
1700 // This method should never be called when the frame is loading.
1701 // Unfortunately, it can happen if a history navigation happens during a
1702 // BeforeUnload or Unload event.
1703 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
1704 // refactored in Blink. See crbug.com/466089
1705 if (is_loading_) {
1706 LOG(WARNING) << "OnDidStartLoading was called twice.";
1707 return;
1708 }
1709
1710 frame_tree_node_->DidStartLoading(to_different_document); 1700 frame_tree_node_->DidStartLoading(to_different_document);
1711 is_loading_ = true; 1701 is_loading_ = true;
1712 } 1702 }
1713 1703
1714 void RenderFrameHostImpl::OnDidStopLoading() { 1704 void RenderFrameHostImpl::OnDidStopLoading() {
1715 // This method should never be called when the frame is not loading. 1705 // This method should never be called when the frame is not loading.
1716 // Unfortunately, it can happen if a history navigation happens during a 1706 // Unfortunately, it can happen if a history navigation happens during a
1717 // BeforeUnload or Unload event. 1707 // BeforeUnload or Unload event.
1718 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been 1708 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
1719 // refactored in Blink. See crbug.com/466089 1709 // refactored in Blink. See crbug.com/466089
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 // message will be received asynchronously from the UI of the browser. But the 1886 // message will be received asynchronously from the UI of the browser. But the
1897 // throbber needs to be kept in sync with what's happening in the UI. For 1887 // throbber needs to be kept in sync with what's happening in the UI. For
1898 // example, the throbber will start immediately when the user navigates even 1888 // example, the throbber will start immediately when the user navigates even
1899 // if the renderer is delayed. There is also an issue with the throbber 1889 // if the renderer is delayed. There is also an issue with the throbber
1900 // starting because the WebUI (which controls whether the favicon is 1890 // starting because the WebUI (which controls whether the favicon is
1901 // displayed) happens synchronously. If the start loading messages was 1891 // displayed) happens synchronously. If the start loading messages was
1902 // asynchronous, then the default favicon would flash in. 1892 // asynchronous, then the default favicon would flash in.
1903 // 1893 //
1904 // Blink doesn't send throb notifications for JavaScript URLs, so it is not 1894 // Blink doesn't send throb notifications for JavaScript URLs, so it is not
1905 // done here either. 1895 // done here either.
1906 if (!common_params.url.SchemeIs(url::kJavaScriptScheme)) 1896 if (!common_params.url.SchemeIs(url::kJavaScriptScheme)) {
1907 frame_tree_node_->DidStartLoading(true); 1897 frame_tree_node_->DidStartLoading(true);
1898 is_loading_ = true;
1899 }
1908 } 1900 }
1909 1901
1910 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) { 1902 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) {
1911 DCHECK(data_url.SchemeIs(url::kDataScheme)); 1903 DCHECK(data_url.SchemeIs(url::kDataScheme));
1912 CommonNavigationParams common_params( 1904 CommonNavigationParams common_params(
1913 data_url, Referrer(), ui::PAGE_TRANSITION_LINK, 1905 data_url, Referrer(), ui::PAGE_TRANSITION_LINK,
1914 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(), 1906 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(),
1915 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), LOFI_OFF, 1907 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), LOFI_OFF,
1916 base::TimeTicks::Now()); 1908 base::TimeTicks::Now());
1917 if (IsBrowserSideNavigationEnabled()) { 1909 if (IsBrowserSideNavigationEnabled()) {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
2238 2230
2239 const image_downloader::ImageDownloaderPtr& 2231 const image_downloader::ImageDownloaderPtr&
2240 RenderFrameHostImpl::GetMojoImageDownloader() { 2232 RenderFrameHostImpl::GetMojoImageDownloader() {
2241 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2233 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
2242 GetServiceRegistry()->ConnectToRemoteService( 2234 GetServiceRegistry()->ConnectToRemoteService(
2243 mojo::GetProxy(&mojo_image_downloader_)); 2235 mojo::GetProxy(&mojo_image_downloader_));
2244 } 2236 }
2245 return mojo_image_downloader_; 2237 return mojo_image_downloader_;
2246 } 2238 }
2247 2239
2240 void RenderFrameHostImpl::ResetLoadingState() {
2241 if (is_loading()) {
2242 // Do not send notifications about load state when swapped out or pending
2243 // swap out.
2244 if (rfh_state_ == STATE_DEFAULT)
2245 OnDidStopLoading();
2246 else
2247 is_loading_ = false;
nasko 2016/01/20 20:58:34 Shouldn't this always be set, regardless of state?
clamy 2016/01/22 13:08:15 OnDidStopLoading will set it. If it is set beforeh
2248 }
2249 }
2250
2248 bool RenderFrameHostImpl::IsSameSiteInstance( 2251 bool RenderFrameHostImpl::IsSameSiteInstance(
2249 RenderFrameHostImpl* other_render_frame_host) { 2252 RenderFrameHostImpl* other_render_frame_host) {
2250 // As a sanity check, make sure the frame belongs to the same BrowserContext. 2253 // As a sanity check, make sure the frame belongs to the same BrowserContext.
2251 CHECK_EQ(GetSiteInstance()->GetBrowserContext(), 2254 CHECK_EQ(GetSiteInstance()->GetBrowserContext(),
2252 other_render_frame_host->GetSiteInstance()->GetBrowserContext()); 2255 other_render_frame_host->GetSiteInstance()->GetBrowserContext());
2253 return GetSiteInstance() == other_render_frame_host->GetSiteInstance(); 2256 return GetSiteInstance() == other_render_frame_host->GetSiteInstance();
2254 } 2257 }
2255 2258
2256 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { 2259 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) {
2257 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode)); 2260 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode));
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2541 *dst = src; 2544 *dst = src;
2542 2545
2543 if (src.routing_id != -1) 2546 if (src.routing_id != -1)
2544 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); 2547 dst->tree_id = RoutingIDToAXTreeID(src.routing_id);
2545 2548
2546 if (src.parent_routing_id != -1) 2549 if (src.parent_routing_id != -1)
2547 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); 2550 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id);
2548 } 2551 }
2549 2552
2550 } // namespace content 2553 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698