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

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

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