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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "content/browser/renderer_host/render_view_host_delegate.h"
15 #include "content/browser/site_instance_impl.h"
16 #include "content/common/content_export.h"
17 #include "content/public/browser/global_request_id.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/common/referrer.h"
21 #include "ui/base/page_transition_types.h"
23 struct FrameMsg_Navigate_Params
;
27 class CrossProcessFrameConnector
;
28 class CrossSiteTransferringRequest
;
30 class InterstitialPageImpl
;
31 class NavigationControllerImpl
;
32 class NavigationEntry
;
33 class NavigationEntryImpl
;
34 class NavigationRequest
;
35 class NavigatorTestWithBrowserSideNavigation
;
36 class RenderFrameHost
;
37 class RenderFrameHostDelegate
;
38 class RenderFrameHostImpl
;
39 class RenderFrameHostManagerTest
;
40 class RenderFrameProxyHost
;
42 class RenderViewHostImpl
;
43 class RenderWidgetHostDelegate
;
44 class RenderWidgetHostView
;
45 class TestWebContents
;
47 struct CommonNavigationParams
;
49 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a
50 // current_frame_host() which is the content currently visible to the user. When
51 // a frame is told to navigate to a different web site (as determined by
52 // SiteInstance), it will replace its current RenderFrameHost with a new
53 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process.
55 // Cross-process navigation works like this:
57 // - RFHM::Navigate determines whether the destination is cross-site, and if so,
58 // it creates a pending_render_frame_host_.
60 // - The pending RFH is created in the "navigations suspended" state, meaning no
61 // navigation messages are sent to its renderer until the beforeunload handler
62 // has a chance to run in the current RFH.
64 // - The current RFH runs its beforeunload handler. If it returns false, we
65 // cancel all the pending logic. Otherwise we allow the pending RFH to send
66 // the navigation request to its renderer.
68 // - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
69 // main resource load from the pending RFH. It creates a
70 // CrossSiteResourceHandler to check whether a process transfer is needed when
71 // the request is ready to commit.
73 // - When RDH receives a response, the BufferedResourceHandler determines
74 // whether it is a navigation type that doesn't commit (e.g. download, 204 or
75 // error page). If so, it sends a message to the new renderer causing it to
76 // cancel the request, and the request (e.g. the download) proceeds. In this
77 // case, the pending RFH will never become the current RFH, but it remains
78 // until the next DidNavigate event for this WebContentsImpl.
80 // - After RDH receives a response and determines that it is safe and not a
81 // download, the CrossSiteResourceHandler checks whether a transfer for a
82 // redirect is needed. If so, it pauses the network response and starts an
83 // identical navigation in a new pending RFH. When the identical request is
84 // later received by RDH, the response is transferred and unpaused.
86 // - Otherwise, the network response commits in the pending RFH's renderer,
87 // which sends a DidCommitProvisionalLoad message back to the browser process.
89 // - RFHM::CommitPending makes visible the new RFH, and initiates the unload
90 // handler in the old RFH. The unload handler will complete in the background.
92 // - RenderFrameHostManager may keep the previous RFH alive as a
93 // RenderFrameProxyHost, to be used (for example) if the user goes back. The
94 // process only stays live if another tab is using it, but if so, the existing
95 // frame relationships will be maintained.
96 class CONTENT_EXPORT RenderFrameHostManager
: public NotificationObserver
{
98 // Functions implemented by our owner that we need.
100 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl
101 // that are required to run this class. The design should probably be better
102 // such that these are more clear.
104 // There is additional complexity that some of the functions we need in
105 // WebContentsImpl are inherited and non-virtual. These are named with
106 // "RenderManager" so that the duplicate implementation of them will be clear.
108 // Functions and parameters whose description are prefixed by PlzNavigate are
109 // part of a navigation refactoring project, currently behind the
110 // enable-browser-side-navigation flag. The idea is to move the logic behind
111 // driving navigations from the renderer to the browser.
112 class CONTENT_EXPORT Delegate
{
114 // Initializes the given renderer if necessary and creates the view ID
115 // corresponding to this view host. If this method is not called and the
116 // process is not shared, then the WebContentsImpl will act as though the
117 // renderer is not running (i.e., it will render "sad tab"). This method is
118 // automatically called from LoadURL. |for_main_frame_navigation| indicates
119 // whether this RenderViewHost is used to render a top-level frame, so the
120 // appropriate RenderWidgetHostView type is used.
121 virtual bool CreateRenderViewForRenderManager(
122 RenderViewHost
* render_view_host
,
124 int proxy_routing_id
,
125 bool for_main_frame_navigation
) = 0;
126 virtual bool CreateRenderFrameForRenderManager(
127 RenderFrameHost
* render_frame_host
,
128 int parent_routing_id
,
129 int proxy_routing_id
) = 0;
130 virtual void BeforeUnloadFiredFromRenderManager(
131 bool proceed
, const base::TimeTicks
& proceed_time
,
132 bool* proceed_to_fire_unload
) = 0;
133 virtual void RenderProcessGoneFromRenderManager(
134 RenderViewHost
* render_view_host
) = 0;
135 virtual void UpdateRenderViewSizeForRenderManager() = 0;
136 virtual void CancelModalDialogsForRenderManager() = 0;
137 virtual void NotifySwappedFromRenderManager(RenderFrameHost
* old_host
,
138 RenderFrameHost
* new_host
,
139 bool is_main_frame
) = 0;
140 // TODO(nasko): This should be removed once extensions no longer use
141 // NotificationService. See https://crbug.com/462682.
142 virtual void NotifyMainFrameSwappedFromRenderManager(
143 RenderViewHost
* old_host
,
144 RenderViewHost
* new_host
) = 0;
145 virtual NavigationControllerImpl
&
146 GetControllerForRenderManager() = 0;
148 // Create swapped out RenderViews in the given SiteInstance for each tab in
149 // the opener chain of this tab, if any. This allows the current tab to
150 // make cross-process script calls to its opener(s). Returns the route ID
151 // of the immediate opener, if one exists (otherwise MSG_ROUTING_NONE).
152 virtual int CreateOpenerRenderViewsForRenderManager(
153 SiteInstance
* instance
) = 0;
155 // Creates a WebUI object for the given URL if one applies. Ownership of the
156 // returned pointer will be passed to the caller. If no WebUI applies,
158 virtual scoped_ptr
<WebUIImpl
> CreateWebUIForRenderManager(
159 const GURL
& url
) = 0;
161 // Returns the navigation entry of the current navigation, or NULL if there
163 virtual NavigationEntry
*
164 GetLastCommittedNavigationEntryForRenderManager() = 0;
166 // Returns true if the location bar should be focused by default rather than
167 // the page contents. The view calls this function when the tab is focused
168 // to see what it should do.
169 virtual bool FocusLocationBarByDefault() = 0;
171 // Focuses the location bar.
172 virtual void SetFocusToLocationBar(bool select_all
) = 0;
174 // Returns true if views created for this delegate should be created in a
176 virtual bool IsHidden() = 0;
179 virtual ~Delegate() {}
182 // Used with FrameTree::ForEach to delete RenderFrameHosts pending shutdown
183 // from a FrameTreeNode's RenderFrameHostManager. Used during destruction of
185 static bool ClearRFHsPendingShutdown(FrameTreeNode
* node
);
187 // All three delegate pointers must be non-NULL and are not owned by this
188 // class. They must outlive this class. The RenderViewHostDelegate and
189 // RenderWidgetHostDelegate are what will be installed into all
190 // RenderViewHosts that are created.
192 // You must call Init() before using this class.
193 RenderFrameHostManager(
194 FrameTreeNode
* frame_tree_node
,
195 RenderFrameHostDelegate
* render_frame_delegate
,
196 RenderViewHostDelegate
* render_view_delegate
,
197 RenderWidgetHostDelegate
* render_widget_delegate
,
199 ~RenderFrameHostManager() override
;
201 // For arguments, see WebContentsImpl constructor.
202 void Init(BrowserContext
* browser_context
,
203 SiteInstance
* site_instance
,
205 int frame_routing_id
);
207 // Returns the currently active RenderFrameHost.
209 // This will be non-NULL between Init() and Shutdown(). You may want to NULL
210 // check it in many cases, however. Windows can send us messages during the
211 // destruction process after it has been shut down.
212 RenderFrameHostImpl
* current_frame_host() const {
213 return render_frame_host_
.get();
216 // TODO(creis): Remove this when we no longer use RVH for navigation.
217 RenderViewHostImpl
* current_host() const;
219 // Returns the view associated with the current RenderViewHost, or NULL if
220 // there is no current one.
221 RenderWidgetHostView
* GetRenderWidgetHostView() const;
223 RenderFrameProxyHost
* GetProxyToParent();
225 // Returns the pending RenderFrameHost, or NULL if there is no pending one.
226 RenderFrameHostImpl
* pending_frame_host() const {
227 return pending_render_frame_host_
.get();
230 // TODO(creis): Remove this when we no longer use RVH for navigation.
231 RenderViewHostImpl
* pending_render_view_host() const;
233 // Returns the current committed Web UI or NULL if none applies.
234 WebUIImpl
* web_ui() const { return web_ui_
.get(); }
236 // Returns the Web UI for the pending navigation, or NULL of none applies.
237 WebUIImpl
* pending_web_ui() const {
238 return pending_web_ui_
.get() ? pending_web_ui_
.get() :
239 pending_and_current_web_ui_
.get();
243 // Returns the speculative WebUI for the navigation (a newly created one or
244 // the current one if it should be reused). If none is set returns nullptr.
245 WebUIImpl
* speculative_web_ui() const {
246 return should_reuse_web_ui_
? web_ui_
.get() : speculative_web_ui_
.get();
249 // Called when we want to instruct the renderer to navigate to the given
250 // navigation entry. It may create a new RenderFrameHost or re-use an existing
251 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one
252 // could not be created.
253 RenderFrameHostImpl
* Navigate(const NavigationEntryImpl
& entry
);
255 // Instructs the various live views to stop. Called when the user directed the
256 // page to stop loading.
259 // Notifies the regular and pending RenderViewHosts that a load is or is not
260 // happening. Even though the message is only for one of them, we don't know
261 // which one so we tell both.
262 void SetIsLoading(bool is_loading
);
264 // Whether to close the tab or not when there is a hang during an unload
265 // handler. If we are mid-crosssite navigation, then we should proceed
266 // with the navigation instead of closing the tab.
267 bool ShouldCloseTabOnUnresponsiveRenderer();
269 // Confirms whether we should close the page or navigate away. This is called
270 // before a cross-site request or before a tab/window is closed (as indicated
271 // by the first parameter) to allow the appropriate renderer to approve or
272 // deny the request. |proceed| indicates whether the user chose to proceed.
273 // |proceed_time| is the time when the request was allowed to proceed.
274 void OnBeforeUnloadACK(bool for_cross_site_transition
,
276 const base::TimeTicks
& proceed_time
);
278 // The |pending_render_frame_host| is ready to commit a page. We should
279 // ensure that the old RenderFrameHost runs its unload handler first and
280 // determine whether a RenderFrameHost transfer is needed.
281 // |cross_site_transferring_request| is NULL if a request is not being
282 // transferred between renderers.
283 void OnCrossSiteResponse(
284 RenderFrameHostImpl
* pending_render_frame_host
,
285 const GlobalRequestID
& global_request_id
,
286 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request
,
287 const std::vector
<GURL
>& transfer_url_chain
,
288 const Referrer
& referrer
,
289 ui::PageTransition page_transition
,
290 bool should_replace_current_entry
);
292 // Received a response from CrossSiteResourceHandler. If the navigation
293 // specifies a transition, this is called and the navigation will not resume
294 // until ResumeResponseDeferredAtStart.
295 void OnDeferredAfterResponseStarted(
296 const GlobalRequestID
& global_request_id
,
297 RenderFrameHostImpl
* pending_render_frame_host
);
299 // Resume navigation paused after receiving response headers.
300 void ResumeResponseDeferredAtStart();
302 // Clear navigation transition data.
303 void ClearNavigationTransitionData();
305 // Called when a renderer's frame navigates.
306 void DidNavigateFrame(RenderFrameHostImpl
* render_frame_host
,
307 bool was_caused_by_user_gesture
);
309 // Called when a renderer sets its opener to null.
310 void DidDisownOpener(RenderFrameHost
* render_frame_host
);
312 // Sets the pending Web UI for the pending navigation, ensuring that the
313 // bindings are appropriate compared to |bindings|.
314 void SetPendingWebUI(const GURL
& url
, int bindings
);
316 // Creates and initializes a RenderFrameHost. The |web_ui| is an optional
317 // input parameter used to double check bindings when swapping back in a
318 // previously existing RenderFrameHost. If |flags| has the
319 // CREATE_RF_SWAPPED_OUT bit set from the CreateRenderFrameFlags enum, it will
320 // initially be placed on the swapped out hosts list. If |view_routing_id_ptr|
321 // is not nullptr it will be set to the routing id of the view associated with
323 scoped_ptr
<RenderFrameHostImpl
> CreateRenderFrame(SiteInstance
* instance
,
327 int* view_routing_id_ptr
);
329 // Helper method to create and initialize a RenderFrameProxyHost and return
331 int CreateRenderFrameProxy(SiteInstance
* instance
);
333 // Sets the passed passed interstitial as the currently showing interstitial.
334 // |interstitial_page| should be non NULL (use the remove_interstitial_page
335 // method to unset the interstitial) and no interstitial page should be set
336 // when there is already a non NULL interstitial page set.
337 void set_interstitial_page(InterstitialPageImpl
* interstitial_page
) {
338 DCHECK(!interstitial_page_
&& interstitial_page
);
339 interstitial_page_
= interstitial_page
;
342 // Unsets the currently showing interstitial.
343 void remove_interstitial_page() {
344 DCHECK(interstitial_page_
);
345 interstitial_page_
= NULL
;
348 // Returns the currently showing interstitial, NULL if no interstitial is
350 InterstitialPageImpl
* interstitial_page() const { return interstitial_page_
; }
352 // NotificationObserver implementation.
353 void Observe(int type
,
354 const NotificationSource
& source
,
355 const NotificationDetails
& details
) override
;
357 // Returns whether the given RenderFrameHost (or its associated
358 // RenderViewHost) is on the list of swapped out RenderFrameHosts.
359 bool IsRVHOnSwappedOutList(RenderViewHostImpl
* rvh
) const;
360 bool IsOnSwappedOutList(RenderFrameHostImpl
* rfh
) const;
362 // Returns the swapped out RenderViewHost or RenderFrameHost for the given
363 // SiteInstance, if any. This method is *deprecated* and
364 // GetRenderFrameProxyHost should be used.
365 RenderViewHostImpl
* GetSwappedOutRenderViewHost(SiteInstance
* instance
) const;
366 RenderFrameProxyHost
* GetRenderFrameProxyHost(
367 SiteInstance
* instance
) const;
369 // Returns whether |render_frame_host| is on the pending deletion list.
370 bool IsPendingDeletion(RenderFrameHostImpl
* render_frame_host
);
372 // If |render_frame_host| is on the pending deletion list, this deletes it.
373 // Returns whether it was deleted.
374 bool DeleteFromPendingList(RenderFrameHostImpl
* render_frame_host
);
376 // Deletes any proxy hosts associated with this node. Used during destruction
377 // of WebContentsImpl.
378 void ResetProxyHosts();
380 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy
381 // that has the given SiteInstance and is associated with this
382 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found.
383 int GetRoutingIdForSiteInstance(SiteInstance
* site_instance
);
386 // Notifies the RFHM that a navigation has begun so that it can speculatively
387 // create a new RenderFrameHost (and potentially a new process) if needed.
388 void BeginNavigation(const NavigationRequest
& request
);
391 // Called (possibly several times) during a navigation to select or create an
392 // appropriate RenderFrameHost for the provided URL. The returned pointer will
393 // be for the current or the speculative RenderFrameHost and the instance is
394 // owned by this manager.
395 RenderFrameHostImpl
* GetFrameHostForNavigation(
396 const NavigationRequest
& request
);
399 // Clean up any state for any ongoing navigation.
400 void CleanUpNavigation();
403 // Clears the speculative members, returning the RenderFrameHost to the caller
405 scoped_ptr
<RenderFrameHostImpl
> UnsetSpeculativeRenderFrameHost();
407 // Notification methods to tell this RenderFrameHostManager that the frame it
408 // is responsible for has started or stopped loading a document.
409 void OnDidStartLoading();
410 void OnDidStopLoading();
412 void EnsureRenderViewInitialized(FrameTreeNode
* source
,
413 RenderViewHostImpl
* render_view_host
,
414 SiteInstance
* instance
);
417 friend class NavigatorTestWithBrowserSideNavigation
;
418 friend class RenderFrameHostManagerTest
;
419 friend class TestWebContents
;
421 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest
,
422 CreateCrossProcessSubframeProxies
);
424 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a
425 // FrameTreeNode's RenderFrameHostManager.
426 static bool ClearProxiesInSiteInstance(int32 site_instance_id
,
427 FrameTreeNode
* node
);
428 // Used with FrameTree::ForEach to reset initialized state of
429 // RenderFrameProxyHosts from a FrameTreeNode's RenderFrameHostManager.
430 static bool ResetProxiesInSiteInstance(int32 site_instance_id
,
431 FrameTreeNode
* node
);
433 // Returns whether this tab should transition to a new renderer for
434 // cross-site URLs. Enabled unless we see the --process-per-tab command line
435 // switch. Can be overridden in unit tests.
436 bool ShouldTransitionCrossSite();
438 // Returns true if for the navigation from |current_effective_url| to
439 // |new_effective_url|, a new SiteInstance and BrowsingInstance should be
440 // created (even if we are in a process model that doesn't usually swap).
441 // This forces a process swap and severs script connections with existing
442 // tabs. Cases where this can happen include transitions between WebUI and
443 // regular web pages. |new_site_instance| may be null.
444 // If there is no current NavigationEntry, then |current_is_view_source_mode|
445 // should be the same as |new_is_view_source_mode|.
447 // We use the effective URL here, since that's what is used in the
448 // SiteInstance's site and when we later call IsSameWebSite. If there is no
449 // current NavigationEntry, check the current SiteInstance's site, which might
450 // already be committed to a Web UI URL (such as the NTP).
451 bool ShouldSwapBrowsingInstancesForNavigation(
452 const GURL
& current_effective_url
,
453 bool current_is_view_source_mode
,
454 SiteInstance
* new_site_instance
,
455 const GURL
& new_effective_url
,
456 bool new_is_view_source_mode
) const;
458 // Creates a new Web UI, ensuring that the bindings are appropriate compared
460 scoped_ptr
<WebUIImpl
> CreateWebUI(const GURL
& url
, int bindings
);
462 // Returns true if it is safe to reuse the current WebUI when navigating from
463 // |current_entry| to |new_url|.
464 bool ShouldReuseWebUI(
465 const NavigationEntry
* current_entry
,
466 const GURL
& new_url
) const;
468 // Returns the SiteInstance to use for the navigation.
469 SiteInstance
* GetSiteInstanceForNavigation(const GURL
& dest_url
,
470 SiteInstance
* source_instance
,
471 SiteInstance
* dest_instance
,
472 ui::PageTransition transition
,
473 bool dest_is_restore
,
474 bool dest_is_view_source_mode
);
476 // Returns an appropriate SiteInstance object for the given |dest_url|,
477 // possibly reusing the current SiteInstance. If --process-per-tab is used,
478 // this is only called when ShouldSwapBrowsingInstancesForNavigation returns
479 // true. |source_instance| is the SiteInstance of the frame that initiated the
480 // navigation. |current_instance| is the SiteInstance of the frame that is
481 // currently navigating. |dest_instance|, is a predetermined SiteInstance
482 // that'll be used if not null.
483 // For example, if you have a parent frame A, which has a child frame B, and
484 // A is trying to change the src attribute of B, this will cause a navigation
485 // where the source SiteInstance is A and B is the current SiteInstance.
486 // This is a helper function for GetSiteInstanceForNavigation.
487 SiteInstance
* GetSiteInstanceForURL(const GURL
& dest_url
,
488 SiteInstance
* source_instance
,
489 SiteInstance
* current_instance
,
490 SiteInstance
* dest_instance
,
491 ui::PageTransition transition
,
492 bool dest_is_restore
,
493 bool dest_is_view_source_mode
,
494 bool force_browsing_instance_swap
);
496 // Determines the appropriate url to use as the current url for SiteInstance
498 const GURL
& GetCurrentURLForSiteInstance(
499 SiteInstance
* current_instance
,
500 NavigationEntry
* current_entry
);
502 // Creates a new RenderFrameHostImpl for the |new_instance| and assign it to
503 // |pending_render_frame_host_| while respecting the opener route if needed
504 // and stores it in pending_render_frame_host_.
505 void CreatePendingRenderFrameHost(SiteInstance
* old_instance
,
506 SiteInstance
* new_instance
,
509 // Ensure that we have created RFHs for the new RFH's opener chain if
510 // we are staying in the same BrowsingInstance. This allows the new RFH
511 // to send cross-process script calls to its opener(s). Returns the opener
512 // route ID to be used for the new RenderView to be created.
513 // |create_render_frame_flags| allows the method to set additional flags.
514 int CreateOpenerRenderViewsIfNeeded(SiteInstance
* old_instance
,
515 SiteInstance
* new_instance
,
516 int* create_render_frame_flags
);
518 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
519 scoped_ptr
<RenderFrameHostImpl
> CreateRenderFrameHost(SiteInstance
* instance
,
521 int frame_routing_id
,
525 // Creates and initializes a speculative RenderFrameHost and/or WebUI for an
526 // ongoing navigation. They might be destroyed and re-created later if the
527 // navigation is redirected to a different SiteInstance.
528 bool CreateSpeculativeRenderFrameHost(const GURL
& url
,
529 SiteInstance
* old_instance
,
530 SiteInstance
* new_instance
,
533 // Sets up the necessary state for a new RenderViewHost with the given opener,
534 // if necessary. It creates a RenderFrameProxy in the target renderer process
535 // with the given |proxy_routing_id|, which is used to route IPC messages when
536 // in swapped out state. Returns early if the RenderViewHost has already been
537 // initialized for another RenderFrameHost.
538 // TODO(creis): opener_route_id is currently for the RenderViewHost but should
539 // be for the RenderFrame, since frames can have openers.
540 bool InitRenderView(RenderViewHostImpl
* render_view_host
,
542 int proxy_routing_id
,
543 bool for_main_frame_navigation
);
545 // Initialization for RenderFrameHost uses the same sequence as InitRenderView
547 bool InitRenderFrame(RenderFrameHostImpl
* render_frame_host
);
549 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
550 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
551 // since there could be Web UI switching as well. Call this for every commit.
552 // If PlzNavigate is enabled the method will set the speculative (not pending)
553 // RenderFrameHost to be the active one.
554 void CommitPending();
556 // Runs the unload handler in the old RenderFrameHost, after the new
557 // RenderFrameHost has committed. |old_render_frame_host| will either be
558 // deleted or put on the pending delete list during this call.
559 void SwapOutOldFrame(scoped_ptr
<RenderFrameHostImpl
> old_render_frame_host
);
561 // Discards a RenderFrameHost that was never made active (for active ones
562 // SwapOutOldFrame is used instead).
563 void DiscardUnusedFrame(scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
565 // Holds |render_frame_host| until it can be deleted when its swap out ACK
567 void MoveToPendingDeleteHosts(
568 scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
570 // Shutdown all RenderFrameProxyHosts in a SiteInstance. This is called to
571 // shutdown frames when all the frames in a SiteInstance are confirmed to be
573 void ShutdownRenderFrameProxyHostsInSiteInstance(int32 site_instance_id
);
575 // Helper method to terminate the pending RenderFrameHost. The frame may be
576 // deleted immediately, or it may be kept around in hopes of later reuse.
577 void CancelPending();
579 // Clears pending_render_frame_host_, returning it to the caller for disposal.
580 scoped_ptr
<RenderFrameHostImpl
> UnsetPendingRenderFrameHost();
582 // Helper method to set the active RenderFrameHost. Returns the old
583 // RenderFrameHost and updates counts.
584 scoped_ptr
<RenderFrameHostImpl
> SetRenderFrameHost(
585 scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
587 RenderFrameHostImpl
* UpdateStateForNavigate(
588 const GURL
& dest_url
,
589 SiteInstance
* source_instance
,
590 SiteInstance
* dest_instance
,
591 ui::PageTransition transition
,
592 bool dest_is_restore
,
593 bool dest_is_view_source_mode
,
594 const GlobalRequestID
& transferred_request_id
,
597 // Called when a renderer process is starting to close. We should not
598 // schedule new navigations in its swapped out RenderFrameHosts after this.
599 void RendererProcessClosing(RenderProcessHost
* render_process_host
);
601 // Helper method to delete a RenderFrameProxyHost from the list, if one exists
602 // for the given |instance|.
603 void DeleteRenderFrameProxyHost(SiteInstance
* instance
);
605 // For use in creating RenderFrameHosts.
606 FrameTreeNode
* frame_tree_node_
;
608 // Our delegate, not owned by us. Guaranteed non-NULL.
611 // Whether a navigation requiring different RenderFrameHosts is pending. This
612 // is either for cross-site requests or when required for the process type
614 // PlzNavigate: |cross_navigation_pending_| is not used for browser-side
616 bool cross_navigation_pending_
;
618 // Implemented by the owner of this class. These delegates are installed into
619 // all the RenderFrameHosts that we create.
620 RenderFrameHostDelegate
* render_frame_delegate_
;
621 RenderViewHostDelegate
* render_view_delegate_
;
622 RenderWidgetHostDelegate
* render_widget_delegate_
;
624 // Our RenderFrameHost and its associated Web UI (if any, will be NULL for
625 // non-WebUI pages). This object is responsible for all communication with
626 // a child RenderFrame instance.
627 // For now, RenderFrameHost keeps a RenderViewHost in its SiteInstance alive.
628 // Eventually, RenderViewHost will be replaced with a page context.
629 scoped_ptr
<RenderFrameHostImpl
> render_frame_host_
;
630 scoped_ptr
<WebUIImpl
> web_ui_
;
632 // A RenderFrameHost used to load a cross-site page. This remains hidden
633 // while a cross-site request is pending until it calls DidNavigate. It may
634 // have an associated Web UI, in which case the Web UI pointer will be non-
637 // The |pending_web_ui_| may be non-NULL even when the
638 // |pending_render_frame_host_| is NULL. This will happen when we're
639 // transitioning between two Web UI pages: the RFH won't be swapped, so the
640 // pending pointer will be unused, but there will be a pending Web UI
641 // associated with the navigation.
642 // Note: This is not used in PlzNavigate.
643 scoped_ptr
<RenderFrameHostImpl
> pending_render_frame_host_
;
645 // If a pending request needs to be transferred to another process, this
646 // owns the request until it's transferred to the new process, so it will be
647 // cleaned up if the navigation is cancelled. Otherwise, this is NULL.
648 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request_
;
650 // Tracks information about any navigation paused after receiving response
652 scoped_ptr
<GlobalRequestID
> response_started_id_
;
654 // If either of these is non-NULL, the pending navigation is to a chrome:
655 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is
656 // used for when they reference the same object. If either is non-NULL, the
657 // other should be NULL.
658 // Note: These are not used in PlzNavigate.
659 scoped_ptr
<WebUIImpl
> pending_web_ui_
;
660 base::WeakPtr
<WebUIImpl
> pending_and_current_web_ui_
;
662 // A map of site instance ID to RenderFrameProxyHosts.
663 typedef base::hash_map
<int32
, RenderFrameProxyHost
*> RenderFrameProxyHostMap
;
664 RenderFrameProxyHostMap proxy_hosts_
;
666 // A list of RenderFrameHosts waiting to shut down after swapping out. We use
667 // a linked list since we expect frequent deletes and no indexed access, and
668 // because sets don't appear to support linked_ptrs.
669 typedef std::list
<linked_ptr
<RenderFrameHostImpl
> > RFHPendingDeleteList
;
670 RFHPendingDeleteList pending_delete_hosts_
;
672 // The intersitial page currently shown if any, not own by this class
673 // (the InterstitialPage is self-owned, it deletes itself when hidden).
674 InterstitialPageImpl
* interstitial_page_
;
676 NotificationRegistrar registrar_
;
679 // These members store a speculative RenderFrameHost and WebUI. They are
680 // created early in a navigation so a renderer process can be started in
681 // parallel, if needed. This is purely a performance optimization and is not
682 // required for correct behavior. The created RenderFrameHost might be
683 // discarded later on if the final URL's SiteInstance isn't compatible with
684 // what was used to create it.
685 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not
687 scoped_ptr
<RenderFrameHostImpl
> speculative_render_frame_host_
;
688 scoped_ptr
<WebUIImpl
> speculative_web_ui_
;
691 // If true at navigation commit time the current WebUI will be kept instead of
692 // creating a new one.
693 bool should_reuse_web_ui_
;
695 base::WeakPtrFactory
<RenderFrameHostManager
> weak_factory_
;
697 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager
);
700 } // namespace content
702 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_