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

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: Rebase + addressed Nasko's nits 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 28 matching lines...) Expand all
255 256
256 RenderFrameHostImpl::~RenderFrameHostImpl() { 257 RenderFrameHostImpl::~RenderFrameHostImpl() {
257 // Release the WebUI instances before all else as the WebUI may accesses the 258 // Release the WebUI instances before all else as the WebUI may accesses the
258 // RenderFrameHost during cleanup. 259 // RenderFrameHost during cleanup.
259 ClearAllWebUI(); 260 ClearAllWebUI();
260 261
261 GetProcess()->RemoveRoute(routing_id_); 262 GetProcess()->RemoveRoute(routing_id_);
262 g_routing_id_frame_map.Get().erase( 263 g_routing_id_frame_map.Get().erase(
263 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 264 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
264 265
266 site_instance_->RemoveObserver(this);
267
265 if (delegate_ && render_frame_created_) 268 if (delegate_ && render_frame_created_)
266 delegate_->RenderFrameDeleted(this); 269 delegate_->RenderFrameDeleted(this);
267 270
268 bool is_active = IsRFHStateActive(rfh_state_); 271 bool is_active = IsRFHStateActive(rfh_state_);
269 272
270 // If this RenderFrameHost is swapped out, it already decremented the active 273 // If this RenderFrameHost is swapped out, it already decremented the active
271 // frame count of the SiteInstance it belongs to. 274 // frame count of the SiteInstance it belongs to.
272 if (is_active) 275 if (is_active)
273 GetSiteInstance()->DecrementActiveFrameCount(); 276 GetSiteInstance()->DecrementActiveFrameCount();
274 277
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach) 513 IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach)
511 IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused, OnFrameFocused) 514 IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused, OnFrameFocused)
512 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoad, 515 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoad,
513 OnDidStartProvisionalLoad) 516 OnDidStartProvisionalLoad)
514 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError, 517 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError,
515 OnDidFailProvisionalLoadWithError) 518 OnDidFailProvisionalLoadWithError)
516 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError, 519 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError,
517 OnDidFailLoadWithError) 520 OnDidFailLoadWithError)
518 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad, 521 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad,
519 OnDidCommitProvisionalLoad(msg)) 522 OnDidCommitProvisionalLoad(msg))
520 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDropNavigation, OnDidDropNavigation)
521 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateState, OnUpdateState) 523 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateState, OnUpdateState)
522 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL) 524 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL)
523 IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted, 525 IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted,
524 OnDocumentOnLoadCompleted) 526 OnDocumentOnLoadCompleted)
525 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK) 527 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK)
526 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK) 528 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK)
527 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu) 529 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu)
528 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse, 530 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse,
529 OnJavaScriptExecuteResponse) 531 OnJavaScriptExecuteResponse)
530 IPC_MESSAGE_HANDLER(FrameHostMsg_VisualStateResponse, 532 IPC_MESSAGE_HANDLER(FrameHostMsg_VisualStateResponse,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 685
684 gfx::NativeViewAccessible 686 gfx::NativeViewAccessible
685 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() { 687 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() {
686 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 688 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
687 render_view_host_->GetWidget()->GetView()); 689 render_view_host_->GetWidget()->GetView());
688 if (view) 690 if (view)
689 return view->AccessibilityGetNativeViewAccessible(); 691 return view->AccessibilityGetNativeViewAccessible();
690 return NULL; 692 return NULL;
691 } 693 }
692 694
695 void RenderFrameHostImpl::RenderProcessGone(SiteInstanceImpl* site_instance) {
696 DCHECK(site_instance == site_instance_.get());
697
698 // The render process is gone, this frame can no longer be loading.
699 ResetLoadingState();
700 }
701
693 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id, 702 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id,
694 int opener_routing_id, 703 int opener_routing_id,
695 int parent_routing_id, 704 int parent_routing_id,
696 int previous_sibling_routing_id) { 705 int previous_sibling_routing_id) {
697 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame"); 706 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame");
698 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; 707 DCHECK(!IsRenderFrameLive()) << "Creating frame twice";
699 708
700 // The process may (if we're sharing a process with another host that already 709 // The process may (if we're sharing a process with another host that already
701 // initialized it) or may not (we have our own process or the old process 710 // initialized it) or may not (we have our own process or the old process
702 // crashed) have been initialized. Calling Init multiple times will be 711 // crashed) have been initialized. Calling Init multiple times will be
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 !validated_params.was_within_same_page) { 1044 !validated_params.was_within_same_page) {
1036 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost()) 1045 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost())
1037 ->StartNewContentRenderingTimeout(); 1046 ->StartNewContentRenderingTimeout();
1038 } 1047 }
1039 1048
1040 // PlzNavigate 1049 // PlzNavigate
1041 if (IsBrowserSideNavigationEnabled()) 1050 if (IsBrowserSideNavigationEnabled())
1042 pending_commit_ = false; 1051 pending_commit_ = false;
1043 } 1052 }
1044 1053
1045 void RenderFrameHostImpl::OnDidDropNavigation() {
1046 // At the end of Navigate(), the FrameTreeNode's DidStartLoading is called to
1047 // force the spinner to start, even if the renderer didn't yet begin the load.
1048 // If it turns out that the renderer dropped the navigation, the spinner needs
1049 // to be turned off.
1050 frame_tree_node_->DidStopLoading();
1051 navigation_handle_.reset();
1052 }
1053
1054 void RenderFrameHostImpl::OnUpdateState(const PageState& state) { 1054 void RenderFrameHostImpl::OnUpdateState(const PageState& state) {
1055 // TODO(creis): Verify the state's ISN matches the last committed FNE. 1055 // TODO(creis): Verify the state's ISN matches the last committed FNE.
1056 1056
1057 // Without this check, the renderer can trick the browser into using 1057 // Without this check, the renderer can trick the browser into using
1058 // filenames it can't access in a future session restore. 1058 // filenames it can't access in a future session restore.
1059 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl. 1059 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl.
1060 if (!render_view_host_->CanAccessFilesOfPageState(state)) { 1060 if (!render_view_host_->CanAccessFilesOfPageState(state)) {
1061 bad_message::ReceivedBadMessage( 1061 bad_message::ReceivedBadMessage(
1062 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE); 1062 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE);
1063 return; 1063 return;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { 1309 frame_tree_node_->render_manager()->IsPendingDeletion(this)) {
1310 render_view_host_->set_is_active(false); 1310 render_view_host_->set_is_active(false);
1311 render_view_host_->set_is_swapped_out(true); 1311 render_view_host_->set_is_swapped_out(true);
1312 } 1312 }
1313 1313
1314 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) { 1314 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) {
1315 // We are now deleted. 1315 // We are now deleted.
1316 return; 1316 return;
1317 } 1317 }
1318 1318
1319 ResetLoadingState();
1320
1319 // If this RFH wasn't pending deletion, then it is now swapped out. 1321 // If this RFH wasn't pending deletion, then it is now swapped out.
1320 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT); 1322 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT);
1321 } 1323 }
1322 1324
1323 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { 1325 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) {
1324 // Validate the URLs in |params|. If the renderer can't request the URLs 1326 // Validate the URLs in |params|. If the renderer can't request the URLs
1325 // directly, don't show them in the context menu. 1327 // directly, don't show them in the context menu.
1326 ContextMenuParams validated_params(params); 1328 ContextMenuParams validated_params(params);
1327 RenderProcessHost* process = GetProcess(); 1329 RenderProcessHost* process = GetProcess();
1328 1330
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin()); 1696 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin());
1695 else 1697 else
1696 delegate_->ExitFullscreenMode(/* will_cause_resize */ true); 1698 delegate_->ExitFullscreenMode(/* will_cause_resize */ true);
1697 1699
1698 // The previous call might change the fullscreen state. We need to make sure 1700 // The previous call might change the fullscreen state. We need to make sure
1699 // the renderer is aware of that, which is done via the resize message. 1701 // the renderer is aware of that, which is done via the resize message.
1700 render_view_host_->GetWidget()->WasResized(); 1702 render_view_host_->GetWidget()->WasResized();
1701 } 1703 }
1702 1704
1703 void RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) { 1705 void RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) {
1704 // Any main frame load to a new document should reset the load since it will 1706 bool was_previously_loading = frame_tree_node_->frame_tree()->IsLoading();
1705 // replace the current page and any frames.
1706 if (to_different_document && !GetParent())
1707 is_loading_ = false;
1708
1709 // This method should never be called when the frame is loading.
1710 // Unfortunately, it can happen if a history navigation happens during a
1711 // BeforeUnload or Unload event.
1712 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
1713 // refactored in Blink. See crbug.com/466089
1714 if (is_loading_) {
1715 LOG(WARNING) << "OnDidStartLoading was called twice.";
1716 return;
1717 }
1718
1719 frame_tree_node_->DidStartLoading(to_different_document);
1720 is_loading_ = true; 1707 is_loading_ = true;
1708 frame_tree_node_->DidStartLoading(to_different_document,
1709 was_previously_loading);
1721 } 1710 }
1722 1711
1723 void RenderFrameHostImpl::OnDidStopLoading() { 1712 void RenderFrameHostImpl::OnDidStopLoading() {
1724 // This method should never be called when the frame is not loading. 1713 // This method should never be called when the frame is not loading.
1725 // Unfortunately, it can happen if a history navigation happens during a 1714 // Unfortunately, it can happen if a history navigation happens during a
1726 // BeforeUnload or Unload event. 1715 // BeforeUnload or Unload event.
1727 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been 1716 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
1728 // refactored in Blink. See crbug.com/466089 1717 // refactored in Blink. See crbug.com/466089
1729 if (!is_loading_) { 1718 if (!is_loading_) {
1730 LOG(WARNING) << "OnDidStopLoading was called twice."; 1719 LOG(WARNING) << "OnDidStopLoading was called twice.";
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 // throbber needs to be kept in sync with what's happening in the UI. For 1895 // throbber needs to be kept in sync with what's happening in the UI. For
1907 // example, the throbber will start immediately when the user navigates even 1896 // example, the throbber will start immediately when the user navigates even
1908 // if the renderer is delayed. There is also an issue with the throbber 1897 // if the renderer is delayed. There is also an issue with the throbber
1909 // starting because the WebUI (which controls whether the favicon is 1898 // starting because the WebUI (which controls whether the favicon is
1910 // displayed) happens synchronously. If the start loading messages was 1899 // displayed) happens synchronously. If the start loading messages was
1911 // asynchronous, then the default favicon would flash in. 1900 // asynchronous, then the default favicon would flash in.
1912 // 1901 //
1913 // Blink doesn't send throb notifications for JavaScript URLs, so it is not 1902 // Blink doesn't send throb notifications for JavaScript URLs, so it is not
1914 // done here either. 1903 // done here either.
1915 if (!common_params.url.SchemeIs(url::kJavaScriptScheme)) 1904 if (!common_params.url.SchemeIs(url::kJavaScriptScheme))
1916 frame_tree_node_->DidStartLoading(true); 1905 OnDidStartLoading(true);
1917 } 1906 }
1918 1907
1919 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) { 1908 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) {
1920 DCHECK(data_url.SchemeIs(url::kDataScheme)); 1909 DCHECK(data_url.SchemeIs(url::kDataScheme));
1921 CommonNavigationParams common_params( 1910 CommonNavigationParams common_params(
1922 data_url, Referrer(), ui::PAGE_TRANSITION_LINK, 1911 data_url, Referrer(), ui::PAGE_TRANSITION_LINK,
1923 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(), 1912 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(),
1924 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), LOFI_OFF, 1913 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), LOFI_OFF,
1925 base::TimeTicks::Now()); 1914 base::TimeTicks::Now());
1926 if (IsBrowserSideNavigationEnabled()) { 1915 if (IsBrowserSideNavigationEnabled()) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 2234
2246 const image_downloader::ImageDownloaderPtr& 2235 const image_downloader::ImageDownloaderPtr&
2247 RenderFrameHostImpl::GetMojoImageDownloader() { 2236 RenderFrameHostImpl::GetMojoImageDownloader() {
2248 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2237 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
2249 GetServiceRegistry()->ConnectToRemoteService( 2238 GetServiceRegistry()->ConnectToRemoteService(
2250 mojo::GetProxy(&mojo_image_downloader_)); 2239 mojo::GetProxy(&mojo_image_downloader_));
2251 } 2240 }
2252 return mojo_image_downloader_; 2241 return mojo_image_downloader_;
2253 } 2242 }
2254 2243
2244 void RenderFrameHostImpl::ResetLoadingState() {
2245 if (is_loading()) {
2246 // When pending deletion, just set the loading state to not loading.
2247 // Otherwise, OnDidStopLoading will take care of that, as well as sending
2248 // notification to the FrameTreeNode about the change in loading state.
2249 if (rfh_state_ != STATE_DEFAULT)
2250 is_loading_ = false;
2251 else
2252 OnDidStopLoading();
2253 }
2254 }
2255
2255 bool RenderFrameHostImpl::IsSameSiteInstance( 2256 bool RenderFrameHostImpl::IsSameSiteInstance(
2256 RenderFrameHostImpl* other_render_frame_host) { 2257 RenderFrameHostImpl* other_render_frame_host) {
2257 // As a sanity check, make sure the frame belongs to the same BrowserContext. 2258 // As a sanity check, make sure the frame belongs to the same BrowserContext.
2258 CHECK_EQ(GetSiteInstance()->GetBrowserContext(), 2259 CHECK_EQ(GetSiteInstance()->GetBrowserContext(),
2259 other_render_frame_host->GetSiteInstance()->GetBrowserContext()); 2260 other_render_frame_host->GetSiteInstance()->GetBrowserContext());
2260 return GetSiteInstance() == other_render_frame_host->GetSiteInstance(); 2261 return GetSiteInstance() == other_render_frame_host->GetSiteInstance();
2261 } 2262 }
2262 2263
2263 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { 2264 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) {
2264 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode)); 2265 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode));
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2559 *dst = src; 2560 *dst = src;
2560 2561
2561 if (src.routing_id != -1) 2562 if (src.routing_id != -1)
2562 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); 2563 dst->tree_id = RoutingIDToAXTreeID(src.routing_id);
2563 2564
2564 if (src.parent_routing_id != -1) 2565 if (src.parent_routing_id != -1)
2565 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); 2566 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id);
2566 } 2567 }
2567 2568
2568 } // namespace content 2569 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.h ('k') | content/browser/frame_host/render_frame_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698