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

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 tests 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 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::RenderProcessGone(SiteInstanceImpl* site_instance) {
692 DCHECK(site_instance == site_instance_.get());
693
694 // The render process is gone, this frame can no longer be loading.
695 ResetLoadingState();
696 }
697
689 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id, 698 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id,
690 int opener_routing_id, 699 int opener_routing_id,
691 int parent_routing_id, 700 int parent_routing_id,
692 int previous_sibling_routing_id) { 701 int previous_sibling_routing_id) {
693 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame"); 702 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame");
694 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; 703 DCHECK(!IsRenderFrameLive()) << "Creating frame twice";
695 704
696 // The process may (if we're sharing a process with another host that already 705 // 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 706 // 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 707 // 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) { 1039 !validated_params.was_within_same_page) {
1031 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost()) 1040 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost())
1032 ->StartNewContentRenderingTimeout(); 1041 ->StartNewContentRenderingTimeout();
1033 } 1042 }
1034 1043
1035 // PlzNavigate 1044 // PlzNavigate
1036 if (IsBrowserSideNavigationEnabled()) 1045 if (IsBrowserSideNavigationEnabled())
1037 pending_commit_ = false; 1046 pending_commit_ = false;
1038 } 1047 }
1039 1048
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) { 1049 void RenderFrameHostImpl::OnUpdateState(const PageState& state) {
1050 // TODO(creis): Verify the state's ISN matches the last committed FNE. 1050 // TODO(creis): Verify the state's ISN matches the last committed FNE.
1051 1051
1052 // Without this check, the renderer can trick the browser into using 1052 // Without this check, the renderer can trick the browser into using
1053 // filenames it can't access in a future session restore. 1053 // filenames it can't access in a future session restore.
1054 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl. 1054 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl.
1055 if (!render_view_host_->CanAccessFilesOfPageState(state)) { 1055 if (!render_view_host_->CanAccessFilesOfPageState(state)) {
1056 bad_message::ReceivedBadMessage( 1056 bad_message::ReceivedBadMessage(
1057 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE); 1057 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE);
1058 return; 1058 return;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { 1300 frame_tree_node_->render_manager()->IsPendingDeletion(this)) {
1301 render_view_host_->set_is_active(false); 1301 render_view_host_->set_is_active(false);
1302 render_view_host_->set_is_swapped_out(true); 1302 render_view_host_->set_is_swapped_out(true);
1303 } 1303 }
1304 1304
1305 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) { 1305 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) {
1306 // We are now deleted. 1306 // We are now deleted.
1307 return; 1307 return;
1308 } 1308 }
1309 1309
1310 ResetLoadingState();
1311
1310 // If this RFH wasn't pending deletion, then it is now swapped out. 1312 // If this RFH wasn't pending deletion, then it is now swapped out.
1311 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT); 1313 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT);
1312 } 1314 }
1313 1315
1314 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { 1316 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) {
1315 // Validate the URLs in |params|. If the renderer can't request the URLs 1317 // Validate the URLs in |params|. If the renderer can't request the URLs
1316 // directly, don't show them in the context menu. 1318 // directly, don't show them in the context menu.
1317 ContextMenuParams validated_params(params); 1319 ContextMenuParams validated_params(params);
1318 RenderProcessHost* process = GetProcess(); 1320 RenderProcessHost* process = GetProcess();
1319 1321
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin()); 1687 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin());
1686 else 1688 else
1687 delegate_->ExitFullscreenMode(/* will_cause_resize */ true); 1689 delegate_->ExitFullscreenMode(/* will_cause_resize */ true);
1688 1690
1689 // The previous call might change the fullscreen state. We need to make sure 1691 // 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. 1692 // the renderer is aware of that, which is done via the resize message.
1691 render_view_host_->GetWidget()->WasResized(); 1693 render_view_host_->GetWidget()->WasResized();
1692 } 1694 }
1693 1695
1694 void RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) { 1696 void RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) {
1695 // Any main frame load to a new document should reset the load since it will 1697 bool was_previously_loading = frame_tree_node_->frame_tree()->IsLoading();
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);
1711 is_loading_ = true; 1698 is_loading_ = true;
1699 frame_tree_node_->DidStartLoading(to_different_document,
1700 was_previously_loading);
1712 } 1701 }
1713 1702
1714 void RenderFrameHostImpl::OnDidStopLoading() { 1703 void RenderFrameHostImpl::OnDidStopLoading() {
1715 // This method should never be called when the frame is not loading. 1704 // This method should never be called when the frame is not loading.
1716 // Unfortunately, it can happen if a history navigation happens during a 1705 // Unfortunately, it can happen if a history navigation happens during a
1717 // BeforeUnload or Unload event. 1706 // BeforeUnload or Unload event.
1718 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been 1707 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
1719 // refactored in Blink. See crbug.com/466089 1708 // refactored in Blink. See crbug.com/466089
1720 if (!is_loading_) { 1709 if (!is_loading_) {
1721 LOG(WARNING) << "OnDidStopLoading was called twice."; 1710 LOG(WARNING) << "OnDidStopLoading was called twice.";
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 // throbber needs to be kept in sync with what's happening in the UI. For 1886 // 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 1887 // 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 1888 // if the renderer is delayed. There is also an issue with the throbber
1900 // starting because the WebUI (which controls whether the favicon is 1889 // starting because the WebUI (which controls whether the favicon is
1901 // displayed) happens synchronously. If the start loading messages was 1890 // displayed) happens synchronously. If the start loading messages was
1902 // asynchronous, then the default favicon would flash in. 1891 // asynchronous, then the default favicon would flash in.
1903 // 1892 //
1904 // Blink doesn't send throb notifications for JavaScript URLs, so it is not 1893 // Blink doesn't send throb notifications for JavaScript URLs, so it is not
1905 // done here either. 1894 // done here either.
1906 if (!common_params.url.SchemeIs(url::kJavaScriptScheme)) 1895 if (!common_params.url.SchemeIs(url::kJavaScriptScheme))
1907 frame_tree_node_->DidStartLoading(true); 1896 OnDidStartLoading(true);
1908 } 1897 }
1909 1898
1910 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) { 1899 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) {
1911 DCHECK(data_url.SchemeIs(url::kDataScheme)); 1900 DCHECK(data_url.SchemeIs(url::kDataScheme));
1912 CommonNavigationParams common_params( 1901 CommonNavigationParams common_params(
1913 data_url, Referrer(), ui::PAGE_TRANSITION_LINK, 1902 data_url, Referrer(), ui::PAGE_TRANSITION_LINK,
1914 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(), 1903 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(),
1915 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), LOFI_OFF, 1904 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), LOFI_OFF,
1916 base::TimeTicks::Now()); 1905 base::TimeTicks::Now());
1917 if (IsBrowserSideNavigationEnabled()) { 1906 if (IsBrowserSideNavigationEnabled()) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 2225
2237 const image_downloader::ImageDownloaderPtr& 2226 const image_downloader::ImageDownloaderPtr&
2238 RenderFrameHostImpl::GetMojoImageDownloader() { 2227 RenderFrameHostImpl::GetMojoImageDownloader() {
2239 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2228 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
2240 GetServiceRegistry()->ConnectToRemoteService( 2229 GetServiceRegistry()->ConnectToRemoteService(
2241 mojo::GetProxy(&mojo_image_downloader_)); 2230 mojo::GetProxy(&mojo_image_downloader_));
2242 } 2231 }
2243 return mojo_image_downloader_; 2232 return mojo_image_downloader_;
2244 } 2233 }
2245 2234
2235 void RenderFrameHostImpl::ResetLoadingState() {
2236 if (is_loading()) {
2237 // When pending deletion, just set the loading state to not loading.
2238 // Otherwise, OnDidStopLoading will take care of that, as well as sending
2239 // notification to the FrameTreeNode about the change in loading state.
2240 if (rfh_state_ != STATE_DEFAULT)
2241 is_loading_ = false;
2242 else
2243 OnDidStopLoading();
2244 }
2245 }
2246
2246 bool RenderFrameHostImpl::IsSameSiteInstance( 2247 bool RenderFrameHostImpl::IsSameSiteInstance(
2247 RenderFrameHostImpl* other_render_frame_host) { 2248 RenderFrameHostImpl* other_render_frame_host) {
2248 // As a sanity check, make sure the frame belongs to the same BrowserContext. 2249 // As a sanity check, make sure the frame belongs to the same BrowserContext.
2249 CHECK_EQ(GetSiteInstance()->GetBrowserContext(), 2250 CHECK_EQ(GetSiteInstance()->GetBrowserContext(),
2250 other_render_frame_host->GetSiteInstance()->GetBrowserContext()); 2251 other_render_frame_host->GetSiteInstance()->GetBrowserContext());
2251 return GetSiteInstance() == other_render_frame_host->GetSiteInstance(); 2252 return GetSiteInstance() == other_render_frame_host->GetSiteInstance();
2252 } 2253 }
2253 2254
2254 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { 2255 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) {
2255 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode)); 2256 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode));
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 *dst = src; 2551 *dst = src;
2551 2552
2552 if (src.routing_id != -1) 2553 if (src.routing_id != -1)
2553 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); 2554 dst->tree_id = RoutingIDToAXTreeID(src.routing_id);
2554 2555
2555 if (src.parent_routing_id != -1) 2556 if (src.parent_routing_id != -1)
2556 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); 2557 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id);
2557 } 2558 }
2558 2559
2559 } // namespace content 2560 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698