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

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: No more changes to SubframeTaskBrowserTest since transfers work Created 4 years, 10 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 pending_web_ui_type_(WebUI::kNoWebUI), 207 pending_web_ui_type_(WebUI::kNoWebUI),
208 should_reuse_web_ui_(false), 208 should_reuse_web_ui_(false),
209 weak_ptr_factory_(this) { 209 weak_ptr_factory_(this) {
210 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 210 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
211 bool hidden = !!(flags & CREATE_RF_HIDDEN); 211 bool hidden = !!(flags & CREATE_RF_HIDDEN);
212 frame_tree_->AddRenderViewHostRef(render_view_host_); 212 frame_tree_->AddRenderViewHostRef(render_view_host_);
213 GetProcess()->AddRoute(routing_id_, this); 213 GetProcess()->AddRoute(routing_id_, this);
214 g_routing_id_frame_map.Get().insert(std::make_pair( 214 g_routing_id_frame_map.Get().insert(std::make_pair(
215 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 215 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
216 this)); 216 this));
217 site_instance_->AddObserver(this);
217 218
218 if (is_swapped_out) { 219 if (is_swapped_out) {
219 rfh_state_ = STATE_SWAPPED_OUT; 220 rfh_state_ = STATE_SWAPPED_OUT;
220 } else { 221 } else {
221 rfh_state_ = STATE_DEFAULT; 222 rfh_state_ = STATE_DEFAULT;
222 GetSiteInstance()->IncrementActiveFrameCount(); 223 GetSiteInstance()->IncrementActiveFrameCount();
223 } 224 }
224 225
225 // New child frames should inherit the nav_entry_id of their parent. 226 // New child frames should inherit the nav_entry_id of their parent.
226 if (frame_tree_node_->parent()) { 227 if (frame_tree_node_->parent()) {
(...skipping 25 matching lines...) Expand all
252 253
253 RenderFrameHostImpl::~RenderFrameHostImpl() { 254 RenderFrameHostImpl::~RenderFrameHostImpl() {
254 // Release the WebUI instances before all else as the WebUI may accesses the 255 // Release the WebUI instances before all else as the WebUI may accesses the
255 // RenderFrameHost during cleanup. 256 // RenderFrameHost during cleanup.
256 ClearAllWebUI(); 257 ClearAllWebUI();
257 258
258 GetProcess()->RemoveRoute(routing_id_); 259 GetProcess()->RemoveRoute(routing_id_);
259 g_routing_id_frame_map.Get().erase( 260 g_routing_id_frame_map.Get().erase(
260 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 261 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
261 262
263 site_instance_->RemoveObserver(this);
264
262 if (delegate_ && render_frame_created_) 265 if (delegate_ && render_frame_created_)
263 delegate_->RenderFrameDeleted(this); 266 delegate_->RenderFrameDeleted(this);
264 267
265 bool is_active = IsRFHStateActive(rfh_state_); 268 bool is_active = IsRFHStateActive(rfh_state_);
266 269
267 // If this RenderFrameHost is swapped out, it already decremented the active 270 // If this RenderFrameHost is swapped out, it already decremented the active
268 // frame count of the SiteInstance it belongs to. 271 // frame count of the SiteInstance it belongs to.
269 if (is_active) 272 if (is_active)
270 GetSiteInstance()->DecrementActiveFrameCount(); 273 GetSiteInstance()->DecrementActiveFrameCount();
271 274
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach) 510 IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach)
508 IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused, OnFrameFocused) 511 IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused, OnFrameFocused)
509 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoad, 512 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoad,
510 OnDidStartProvisionalLoad) 513 OnDidStartProvisionalLoad)
511 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError, 514 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError,
512 OnDidFailProvisionalLoadWithError) 515 OnDidFailProvisionalLoadWithError)
513 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError, 516 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError,
514 OnDidFailLoadWithError) 517 OnDidFailLoadWithError)
515 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad, 518 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad,
516 OnDidCommitProvisionalLoad(msg)) 519 OnDidCommitProvisionalLoad(msg))
517 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDropNavigation, OnDidDropNavigation)
518 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateState, OnUpdateState) 520 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateState, OnUpdateState)
519 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL) 521 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL)
520 IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted, 522 IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted,
521 OnDocumentOnLoadCompleted) 523 OnDocumentOnLoadCompleted)
522 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK) 524 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK)
523 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK) 525 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK)
524 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu) 526 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu)
525 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse, 527 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse,
526 OnJavaScriptExecuteResponse) 528 OnJavaScriptExecuteResponse)
527 IPC_MESSAGE_HANDLER(FrameHostMsg_VisualStateResponse, 529 IPC_MESSAGE_HANDLER(FrameHostMsg_VisualStateResponse,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 682
681 gfx::NativeViewAccessible 683 gfx::NativeViewAccessible
682 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() { 684 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() {
683 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 685 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
684 render_view_host_->GetWidget()->GetView()); 686 render_view_host_->GetWidget()->GetView());
685 if (view) 687 if (view)
686 return view->AccessibilityGetNativeViewAccessible(); 688 return view->AccessibilityGetNativeViewAccessible();
687 return NULL; 689 return NULL;
688 } 690 }
689 691
692 void RenderFrameHostImpl::RenderProcessGone(SiteInstanceImpl* site_instance) {
693 DCHECK(site_instance == site_instance_.get());
694
695 // The render process is gone, this frame can no longer be loading.
696 ResetLoadingState();
697 }
698
690 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id, 699 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id,
691 int opener_routing_id, 700 int opener_routing_id,
692 int parent_routing_id, 701 int parent_routing_id,
693 int previous_sibling_routing_id) { 702 int previous_sibling_routing_id) {
694 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame"); 703 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame");
695 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; 704 DCHECK(!IsRenderFrameLive()) << "Creating frame twice";
696 705
697 // The process may (if we're sharing a process with another host that already 706 // The process may (if we're sharing a process with another host that already
698 // initialized it) or may not (we have our own process or the old process 707 // initialized it) or may not (we have our own process or the old process
699 // crashed) have been initialized. Calling Init multiple times will be 708 // crashed) have been initialized. Calling Init multiple times will be
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 !validated_params.was_within_same_page) { 1038 !validated_params.was_within_same_page) {
1030 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost()) 1039 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost())
1031 ->StartNewContentRenderingTimeout(); 1040 ->StartNewContentRenderingTimeout();
1032 } 1041 }
1033 1042
1034 // PlzNavigate 1043 // PlzNavigate
1035 if (IsBrowserSideNavigationEnabled()) 1044 if (IsBrowserSideNavigationEnabled())
1036 pending_commit_ = false; 1045 pending_commit_ = false;
1037 } 1046 }
1038 1047
1039 void RenderFrameHostImpl::OnDidDropNavigation() {
1040 // At the end of Navigate(), the FrameTreeNode's DidStartLoading is called to
1041 // force the spinner to start, even if the renderer didn't yet begin the load.
1042 // If it turns out that the renderer dropped the navigation, the spinner needs
1043 // to be turned off.
1044 frame_tree_node_->DidStopLoading();
1045 navigation_handle_.reset();
1046 }
1047
1048 void RenderFrameHostImpl::OnUpdateState(const PageState& state) { 1048 void RenderFrameHostImpl::OnUpdateState(const PageState& state) {
1049 // TODO(creis): Verify the state's ISN matches the last committed FNE. 1049 // TODO(creis): Verify the state's ISN matches the last committed FNE.
1050 1050
1051 // Without this check, the renderer can trick the browser into using 1051 // Without this check, the renderer can trick the browser into using
1052 // filenames it can't access in a future session restore. 1052 // filenames it can't access in a future session restore.
1053 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl. 1053 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl.
1054 if (!render_view_host_->CanAccessFilesOfPageState(state)) { 1054 if (!render_view_host_->CanAccessFilesOfPageState(state)) {
1055 bad_message::ReceivedBadMessage( 1055 bad_message::ReceivedBadMessage(
1056 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE); 1056 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE);
1057 return; 1057 return;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { 1303 frame_tree_node_->render_manager()->IsPendingDeletion(this)) {
1304 render_view_host_->set_is_active(false); 1304 render_view_host_->set_is_active(false);
1305 render_view_host_->set_is_swapped_out(true); 1305 render_view_host_->set_is_swapped_out(true);
1306 } 1306 }
1307 1307
1308 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) { 1308 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) {
1309 // We are now deleted. 1309 // We are now deleted.
1310 return; 1310 return;
1311 } 1311 }
1312 1312
1313 ResetLoadingState();
1314
1313 // 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.
1314 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT); 1316 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT);
1315 } 1317 }
1316 1318
1317 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { 1319 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) {
1318 // 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
1319 // directly, don't show them in the context menu. 1321 // directly, don't show them in the context menu.
1320 ContextMenuParams validated_params(params); 1322 ContextMenuParams validated_params(params);
1321 RenderProcessHost* process = GetProcess(); 1323 RenderProcessHost* process = GetProcess();
1322 1324
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin()); 1690 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin());
1689 else 1691 else
1690 delegate_->ExitFullscreenMode(/* will_cause_resize */ true); 1692 delegate_->ExitFullscreenMode(/* will_cause_resize */ true);
1691 1693
1692 // 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
1693 // 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.
1694 render_view_host_->GetWidget()->WasResized(); 1696 render_view_host_->GetWidget()->WasResized();
1695 } 1697 }
1696 1698
1697 void RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) { 1699 void RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) {
1698 // Any main frame load to a new document should reset the load since it will 1700 bool was_previously_loading = frame_tree_node_->frame_tree()->IsLoading();
1699 // replace the current page and any frames.
1700 if (to_different_document && !GetParent())
1701 is_loading_ = false;
1702
1703 // This method should never be called when the frame is loading.
1704 // Unfortunately, it can happen if a history navigation happens during a
1705 // BeforeUnload or Unload event.
1706 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
1707 // refactored in Blink. See crbug.com/466089
1708 if (is_loading_) {
1709 LOG(WARNING) << "OnDidStartLoading was called twice.";
1710 return;
1711 }
1712
1713 frame_tree_node_->DidStartLoading(to_different_document);
1714 is_loading_ = true; 1701 is_loading_ = true;
1702 frame_tree_node_->DidStartLoading(to_different_document,
1703 was_previously_loading);
1715 } 1704 }
1716 1705
1717 void RenderFrameHostImpl::OnDidStopLoading() { 1706 void RenderFrameHostImpl::OnDidStopLoading() {
1718 // This method should never be called when the frame is not loading. 1707 // This method should never be called when the frame is not loading.
1719 // Unfortunately, it can happen if a history navigation happens during a 1708 // Unfortunately, it can happen if a history navigation happens during a
1720 // BeforeUnload or Unload event. 1709 // BeforeUnload or Unload event.
1721 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been 1710 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
1722 // refactored in Blink. See crbug.com/466089 1711 // refactored in Blink. See crbug.com/466089
1723 if (!is_loading_) { 1712 if (!is_loading_) {
1724 LOG(WARNING) << "OnDidStopLoading was called twice."; 1713 LOG(WARNING) << "OnDidStopLoading was called twice.";
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 // throbber needs to be kept in sync with what's happening in the UI. For 1889 // throbber needs to be kept in sync with what's happening in the UI. For
1901 // example, the throbber will start immediately when the user navigates even 1890 // example, the throbber will start immediately when the user navigates even
1902 // if the renderer is delayed. There is also an issue with the throbber 1891 // if the renderer is delayed. There is also an issue with the throbber
1903 // starting because the WebUI (which controls whether the favicon is 1892 // starting because the WebUI (which controls whether the favicon is
1904 // displayed) happens synchronously. If the start loading messages was 1893 // displayed) happens synchronously. If the start loading messages was
1905 // asynchronous, then the default favicon would flash in. 1894 // asynchronous, then the default favicon would flash in.
1906 // 1895 //
1907 // Blink doesn't send throb notifications for JavaScript URLs, so it is not 1896 // Blink doesn't send throb notifications for JavaScript URLs, so it is not
1908 // done here either. 1897 // done here either.
1909 if (!common_params.url.SchemeIs(url::kJavaScriptScheme)) 1898 if (!common_params.url.SchemeIs(url::kJavaScriptScheme))
1910 frame_tree_node_->DidStartLoading(true); 1899 OnDidStartLoading(true);
1911 } 1900 }
1912 1901
1913 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) { 1902 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) {
1914 DCHECK(data_url.SchemeIs(url::kDataScheme)); 1903 DCHECK(data_url.SchemeIs(url::kDataScheme));
1915 CommonNavigationParams common_params( 1904 CommonNavigationParams common_params(
1916 data_url, Referrer(), ui::PAGE_TRANSITION_LINK, 1905 data_url, Referrer(), ui::PAGE_TRANSITION_LINK,
1917 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(), 1906 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(),
1918 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), LOFI_OFF, 1907 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), LOFI_OFF,
1919 base::TimeTicks::Now()); 1908 base::TimeTicks::Now());
1920 if (IsBrowserSideNavigationEnabled()) { 1909 if (IsBrowserSideNavigationEnabled()) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 2228
2240 const image_downloader::ImageDownloaderPtr& 2229 const image_downloader::ImageDownloaderPtr&
2241 RenderFrameHostImpl::GetMojoImageDownloader() { 2230 RenderFrameHostImpl::GetMojoImageDownloader() {
2242 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2231 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
2243 GetServiceRegistry()->ConnectToRemoteService( 2232 GetServiceRegistry()->ConnectToRemoteService(
2244 mojo::GetProxy(&mojo_image_downloader_)); 2233 mojo::GetProxy(&mojo_image_downloader_));
2245 } 2234 }
2246 return mojo_image_downloader_; 2235 return mojo_image_downloader_;
2247 } 2236 }
2248 2237
2238 void RenderFrameHostImpl::ResetLoadingState() {
2239 if (is_loading()) {
2240 // When pending deletion, just set the loading state to not loading.
2241 // Otherwise, OnDidStopLoading will take care of that, as well as sending
2242 // notification to the FrameTreeNode about the change in loading state.
2243 if (rfh_state_ != STATE_DEFAULT)
2244 is_loading_ = false;
2245 else
2246 OnDidStopLoading();
2247 }
2248 }
2249
2249 bool RenderFrameHostImpl::IsSameSiteInstance( 2250 bool RenderFrameHostImpl::IsSameSiteInstance(
2250 RenderFrameHostImpl* other_render_frame_host) { 2251 RenderFrameHostImpl* other_render_frame_host) {
2251 // As a sanity check, make sure the frame belongs to the same BrowserContext. 2252 // As a sanity check, make sure the frame belongs to the same BrowserContext.
2252 CHECK_EQ(GetSiteInstance()->GetBrowserContext(), 2253 CHECK_EQ(GetSiteInstance()->GetBrowserContext(),
2253 other_render_frame_host->GetSiteInstance()->GetBrowserContext()); 2254 other_render_frame_host->GetSiteInstance()->GetBrowserContext());
2254 return GetSiteInstance() == other_render_frame_host->GetSiteInstance(); 2255 return GetSiteInstance() == other_render_frame_host->GetSiteInstance();
2255 } 2256 }
2256 2257
2257 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { 2258 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) {
2258 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode)); 2259 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode));
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 *dst = src; 2554 *dst = src;
2554 2555
2555 if (src.routing_id != -1) 2556 if (src.routing_id != -1)
2556 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); 2557 dst->tree_id = RoutingIDToAXTreeID(src.routing_id);
2557 2558
2558 if (src.parent_routing_id != -1) 2559 if (src.parent_routing_id != -1)
2559 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); 2560 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id);
2560 } 2561 }
2561 2562
2562 } // namespace content 2563 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698