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

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

Issue 1693353002: Reland #2 Remove the is_loading_ field from WebContentsImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits + rebase 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach) 517 IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach)
515 IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused, OnFrameFocused) 518 IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused, OnFrameFocused)
516 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoad, 519 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoad,
517 OnDidStartProvisionalLoad) 520 OnDidStartProvisionalLoad)
518 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError, 521 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError,
519 OnDidFailProvisionalLoadWithError) 522 OnDidFailProvisionalLoadWithError)
520 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError, 523 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError,
521 OnDidFailLoadWithError) 524 OnDidFailLoadWithError)
522 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad, 525 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad,
523 OnDidCommitProvisionalLoad(msg)) 526 OnDidCommitProvisionalLoad(msg))
524 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDropNavigation, OnDidDropNavigation)
525 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateState, OnUpdateState) 527 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateState, OnUpdateState)
526 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL) 528 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL)
527 IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted, 529 IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted,
528 OnDocumentOnLoadCompleted) 530 OnDocumentOnLoadCompleted)
529 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK) 531 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK)
530 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK) 532 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK)
531 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu) 533 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu)
532 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse, 534 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse,
533 OnJavaScriptExecuteResponse) 535 OnJavaScriptExecuteResponse)
534 IPC_MESSAGE_HANDLER(FrameHostMsg_VisualStateResponse, 536 IPC_MESSAGE_HANDLER(FrameHostMsg_VisualStateResponse,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 689
688 gfx::NativeViewAccessible 690 gfx::NativeViewAccessible
689 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() { 691 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() {
690 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 692 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
691 render_view_host_->GetWidget()->GetView()); 693 render_view_host_->GetWidget()->GetView());
692 if (view) 694 if (view)
693 return view->AccessibilityGetNativeViewAccessible(); 695 return view->AccessibilityGetNativeViewAccessible();
694 return NULL; 696 return NULL;
695 } 697 }
696 698
699 void RenderFrameHostImpl::RenderProcessGone(SiteInstanceImpl* site_instance) {
700 DCHECK_EQ(site_instance_.get(), site_instance);
701
702 // The renderer process is gone, so this frame can no longer be loading.
703 ResetLoadingState();
704 }
705
697 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id, 706 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id,
698 int opener_routing_id, 707 int opener_routing_id,
699 int parent_routing_id, 708 int parent_routing_id,
700 int previous_sibling_routing_id) { 709 int previous_sibling_routing_id) {
701 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame"); 710 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame");
702 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; 711 DCHECK(!IsRenderFrameLive()) << "Creating frame twice";
703 712
704 // The process may (if we're sharing a process with another host that already 713 // The process may (if we're sharing a process with another host that already
705 // initialized it) or may not (we have our own process or the old process 714 // initialized it) or may not (we have our own process or the old process
706 // crashed) have been initialized. Calling Init multiple times will be 715 // crashed) have been initialized. Calling Init multiple times will be
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 !validated_params.was_within_same_page) { 1048 !validated_params.was_within_same_page) {
1040 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost()) 1049 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost())
1041 ->StartNewContentRenderingTimeout(); 1050 ->StartNewContentRenderingTimeout();
1042 } 1051 }
1043 1052
1044 // PlzNavigate 1053 // PlzNavigate
1045 if (IsBrowserSideNavigationEnabled()) 1054 if (IsBrowserSideNavigationEnabled())
1046 pending_commit_ = false; 1055 pending_commit_ = false;
1047 } 1056 }
1048 1057
1049 void RenderFrameHostImpl::OnDidDropNavigation() {
1050 // At the end of Navigate(), the FrameTreeNode's DidStartLoading is called to
1051 // force the spinner to start, even if the renderer didn't yet begin the load.
1052 // If it turns out that the renderer dropped the navigation, the spinner needs
1053 // to be turned off.
1054 frame_tree_node_->DidStopLoading();
1055 navigation_handle_.reset();
1056 }
1057
1058 void RenderFrameHostImpl::OnUpdateState(const PageState& state) { 1058 void RenderFrameHostImpl::OnUpdateState(const PageState& state) {
1059 // TODO(creis): Verify the state's ISN matches the last committed FNE. 1059 // TODO(creis): Verify the state's ISN matches the last committed FNE.
1060 1060
1061 // Without this check, the renderer can trick the browser into using 1061 // Without this check, the renderer can trick the browser into using
1062 // filenames it can't access in a future session restore. 1062 // filenames it can't access in a future session restore.
1063 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl. 1063 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl.
1064 if (!render_view_host_->CanAccessFilesOfPageState(state)) { 1064 if (!render_view_host_->CanAccessFilesOfPageState(state)) {
1065 bad_message::ReceivedBadMessage( 1065 bad_message::ReceivedBadMessage(
1066 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE); 1066 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE);
1067 return; 1067 return;
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin()); 1698 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin());
1699 else 1699 else
1700 delegate_->ExitFullscreenMode(/* will_cause_resize */ true); 1700 delegate_->ExitFullscreenMode(/* will_cause_resize */ true);
1701 1701
1702 // The previous call might change the fullscreen state. We need to make sure 1702 // The previous call might change the fullscreen state. We need to make sure
1703 // the renderer is aware of that, which is done via the resize message. 1703 // the renderer is aware of that, which is done via the resize message.
1704 render_view_host_->GetWidget()->WasResized(); 1704 render_view_host_->GetWidget()->WasResized();
1705 } 1705 }
1706 1706
1707 void RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) { 1707 void RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) {
1708 // Any main frame load to a new document should reset the load since it will 1708 bool was_previously_loading = frame_tree_node_->frame_tree()->IsLoading();
1709 // replace the current page and any frames. 1709 is_loading_ = true;
1710 if (to_different_document && !GetParent())
1711 is_loading_ = false;
1712 1710
1713 // This method should never be called when the frame is loading. 1711 // Only inform the FrameTreeNode of a change in load state if the load state
1714 // Unfortunately, it can happen if a history navigation happens during a 1712 // of this RenderFrameHost is being tracked.
1715 // BeforeUnload or Unload event. 1713 if (rfh_state_ == STATE_DEFAULT) {
1716 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been 1714 frame_tree_node_->DidStartLoading(to_different_document,
1717 // refactored in Blink. See crbug.com/466089 1715 was_previously_loading);
1718 if (is_loading_) {
1719 LOG(WARNING) << "OnDidStartLoading was called twice.";
1720 return;
1721 } 1716 }
1722
1723 frame_tree_node_->DidStartLoading(to_different_document);
1724 is_loading_ = true;
1725 } 1717 }
1726 1718
1727 void RenderFrameHostImpl::OnDidStopLoading() { 1719 void RenderFrameHostImpl::OnDidStopLoading() {
1728 // This method should never be called when the frame is not loading. 1720 // This method should never be called when the frame is not loading.
1729 // Unfortunately, it can happen if a history navigation happens during a 1721 // Unfortunately, it can happen if a history navigation happens during a
1730 // BeforeUnload or Unload event. 1722 // BeforeUnload or Unload event.
1731 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been 1723 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
1732 // refactored in Blink. See crbug.com/466089 1724 // refactored in Blink. See crbug.com/466089
1733 if (!is_loading_) { 1725 if (!is_loading_) {
1734 LOG(WARNING) << "OnDidStopLoading was called twice."; 1726 LOG(WARNING) << "OnDidStopLoading was called twice.";
1735 return; 1727 return;
1736 } 1728 }
1737 1729
1738 is_loading_ = false; 1730 is_loading_ = false;
1739 frame_tree_node_->DidStopLoading();
1740 navigation_handle_.reset(); 1731 navigation_handle_.reset();
1732
1733 // Only inform the FrameTreeNode of a change in load state if the load state
1734 // of this RenderFrameHost is being tracked.
1735 if (rfh_state_ == STATE_DEFAULT)
1736 frame_tree_node_->DidStopLoading();
1741 } 1737 }
1742 1738
1743 void RenderFrameHostImpl::OnDidChangeLoadProgress(double load_progress) { 1739 void RenderFrameHostImpl::OnDidChangeLoadProgress(double load_progress) {
1744 frame_tree_node_->DidChangeLoadProgress(load_progress); 1740 frame_tree_node_->DidChangeLoadProgress(load_progress);
1745 } 1741 }
1746 1742
1747 void RenderFrameHostImpl::OnSerializeAsMHTMLResponse( 1743 void RenderFrameHostImpl::OnSerializeAsMHTMLResponse(
1748 int job_id, 1744 int job_id,
1749 bool success, 1745 bool success,
1750 const std::set<std::string>& digests_of_uris_of_serialized_resources) { 1746 const std::set<std::string>& digests_of_uris_of_serialized_resources) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 // 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
1911 // example, the throbber will start immediately when the user navigates even 1907 // example, the throbber will start immediately when the user navigates even
1912 // 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
1913 // starting because the WebUI (which controls whether the favicon is 1909 // starting because the WebUI (which controls whether the favicon is
1914 // displayed) happens synchronously. If the start loading messages was 1910 // displayed) happens synchronously. If the start loading messages was
1915 // asynchronous, then the default favicon would flash in. 1911 // asynchronous, then the default favicon would flash in.
1916 // 1912 //
1917 // 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
1918 // done here either. 1914 // done here either.
1919 if (!common_params.url.SchemeIs(url::kJavaScriptScheme)) 1915 if (!common_params.url.SchemeIs(url::kJavaScriptScheme))
1920 frame_tree_node_->DidStartLoading(true); 1916 OnDidStartLoading(true);
1921 } 1917 }
1922 1918
1923 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) { 1919 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) {
1924 DCHECK(data_url.SchemeIs(url::kDataScheme)); 1920 DCHECK(data_url.SchemeIs(url::kDataScheme));
1925 CommonNavigationParams common_params( 1921 CommonNavigationParams common_params(
1926 data_url, Referrer(), ui::PAGE_TRANSITION_LINK, 1922 data_url, Referrer(), ui::PAGE_TRANSITION_LINK,
1927 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(), 1923 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(),
1928 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), LOFI_OFF, 1924 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), LOFI_OFF,
1929 base::TimeTicks::Now()); 1925 base::TimeTicks::Now());
1930 if (IsBrowserSideNavigationEnabled()) { 1926 if (IsBrowserSideNavigationEnabled()) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2249 2245
2250 const image_downloader::ImageDownloaderPtr& 2246 const image_downloader::ImageDownloaderPtr&
2251 RenderFrameHostImpl::GetMojoImageDownloader() { 2247 RenderFrameHostImpl::GetMojoImageDownloader() {
2252 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { 2248 if (!mojo_image_downloader_.get() && GetServiceRegistry()) {
2253 GetServiceRegistry()->ConnectToRemoteService( 2249 GetServiceRegistry()->ConnectToRemoteService(
2254 mojo::GetProxy(&mojo_image_downloader_)); 2250 mojo::GetProxy(&mojo_image_downloader_));
2255 } 2251 }
2256 return mojo_image_downloader_; 2252 return mojo_image_downloader_;
2257 } 2253 }
2258 2254
2255 void RenderFrameHostImpl::ResetLoadingState() {
2256 if (is_loading()) {
2257 // When pending deletion, just set the loading state to not loading.
2258 // Otherwise, OnDidStopLoading will take care of that, as well as sending
2259 // notification to the FrameTreeNode about the change in loading state.
2260 if (rfh_state_ != STATE_DEFAULT)
2261 is_loading_ = false;
2262 else
2263 OnDidStopLoading();
2264 }
2265 }
2266
2259 bool RenderFrameHostImpl::IsSameSiteInstance( 2267 bool RenderFrameHostImpl::IsSameSiteInstance(
2260 RenderFrameHostImpl* other_render_frame_host) { 2268 RenderFrameHostImpl* other_render_frame_host) {
2261 // As a sanity check, make sure the frame belongs to the same BrowserContext. 2269 // As a sanity check, make sure the frame belongs to the same BrowserContext.
2262 CHECK_EQ(GetSiteInstance()->GetBrowserContext(), 2270 CHECK_EQ(GetSiteInstance()->GetBrowserContext(),
2263 other_render_frame_host->GetSiteInstance()->GetBrowserContext()); 2271 other_render_frame_host->GetSiteInstance()->GetBrowserContext());
2264 return GetSiteInstance() == other_render_frame_host->GetSiteInstance(); 2272 return GetSiteInstance() == other_render_frame_host->GetSiteInstance();
2265 } 2273 }
2266 2274
2267 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { 2275 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) {
2268 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode)); 2276 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode));
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2569 *dst = src; 2577 *dst = src;
2570 2578
2571 if (src.routing_id != -1) 2579 if (src.routing_id != -1)
2572 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); 2580 dst->tree_id = RoutingIDToAXTreeID(src.routing_id);
2573 2581
2574 if (src.parent_routing_id != -1) 2582 if (src.parent_routing_id != -1)
2575 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); 2583 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id);
2576 } 2584 }
2577 2585
2578 } // namespace content 2586 } // 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