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"
22 #include "url/origin.h"
26 class CrossProcessFrameConnector
;
27 class CrossSiteTransferringRequest
;
28 class FrameNavigationEntry
;
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
;
48 struct FrameReplicationState
;
50 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a
51 // current_frame_host() which is the content currently visible to the user. When
52 // a frame is told to navigate to a different web site (as determined by
53 // SiteInstance), it will replace its current RenderFrameHost with a new
54 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process.
56 // Cross-process navigation works like this:
58 // - RFHM::Navigate determines whether the destination is cross-site, and if so,
59 // it creates a pending_render_frame_host_.
61 // - The pending RFH is created in the "navigations suspended" state, meaning no
62 // navigation messages are sent to its renderer until the beforeunload handler
63 // has a chance to run in the current RFH.
65 // - The current RFH runs its beforeunload handler. If it returns false, we
66 // cancel all the pending logic. Otherwise we allow the pending RFH to send
67 // the navigation request to its renderer.
69 // - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
70 // main resource load from the pending RFH. It creates a
71 // CrossSiteResourceHandler to check whether a process transfer is needed when
72 // the request is ready to commit.
74 // - When RDH receives a response, the MimeTypeResourceHandler determines
75 // whether it is a navigation type that doesn't commit (e.g. download, 204 or
76 // error page). If so, it sends a message to the new renderer causing it to
77 // cancel the request, and the request (e.g. the download) proceeds. In this
78 // case, the pending RFH will never become the current RFH, but it remains
79 // until the next DidNavigate event for this WebContentsImpl.
81 // - After RDH receives a response and determines that it is safe and not a
82 // download, the CrossSiteResourceHandler checks whether a transfer for a
83 // redirect is needed. If so, it pauses the network response and starts an
84 // identical navigation in a new pending RFH. When the identical request is
85 // later received by RDH, the response is transferred and unpaused.
87 // - Otherwise, the network response commits in the pending RFH's renderer,
88 // which sends a DidCommitProvisionalLoad message back to the browser process.
90 // - RFHM::CommitPending makes visible the new RFH, and initiates the unload
91 // handler in the old RFH. The unload handler will complete in the background.
93 // - RenderFrameHostManager may keep the previous RFH alive as a
94 // RenderFrameProxyHost, to be used (for example) if the user goes back. The
95 // process only stays live if another tab is using it, but if so, the existing
96 // frame relationships will be maintained.
97 class CONTENT_EXPORT RenderFrameHostManager
: public NotificationObserver
{
99 // Functions implemented by our owner that we need.
101 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl
102 // that are required to run this class. The design should probably be better
103 // such that these are more clear.
105 // There is additional complexity that some of the functions we need in
106 // WebContentsImpl are inherited and non-virtual. These are named with
107 // "RenderManager" so that the duplicate implementation of them will be clear.
109 // Functions and parameters whose description are prefixed by PlzNavigate are
110 // part of a navigation refactoring project, currently behind the
111 // enable-browser-side-navigation flag. The idea is to move the logic behind
112 // driving navigations from the renderer to the browser.
113 class CONTENT_EXPORT Delegate
{
115 // Initializes the given renderer if necessary and creates the view ID
116 // corresponding to this view host. If this method is not called and the
117 // process is not shared, then the WebContentsImpl will act as though the
118 // renderer is not running (i.e., it will render "sad tab"). This method is
119 // automatically called from LoadURL. |for_main_frame_navigation| indicates
120 // whether this RenderViewHost is used to render a top-level frame, so the
121 // appropriate RenderWidgetHostView type is used.
122 virtual bool CreateRenderViewForRenderManager(
123 RenderViewHost
* render_view_host
,
125 int proxy_routing_id
,
126 const FrameReplicationState
& replicated_frame_state
,
127 bool for_main_frame_navigation
) = 0;
128 virtual bool CreateRenderFrameForRenderManager(
129 RenderFrameHost
* render_frame_host
,
130 int parent_routing_id
,
131 int previous_sibling_routing_id
,
132 int proxy_routing_id
) = 0;
133 virtual void BeforeUnloadFiredFromRenderManager(
134 bool proceed
, const base::TimeTicks
& proceed_time
,
135 bool* proceed_to_fire_unload
) = 0;
136 virtual void RenderProcessGoneFromRenderManager(
137 RenderViewHost
* render_view_host
) = 0;
138 virtual void UpdateRenderViewSizeForRenderManager() = 0;
139 virtual void CancelModalDialogsForRenderManager() = 0;
140 virtual void NotifySwappedFromRenderManager(RenderFrameHost
* old_host
,
141 RenderFrameHost
* new_host
,
142 bool is_main_frame
) = 0;
143 // TODO(nasko): This should be removed once extensions no longer use
144 // NotificationService. See https://crbug.com/462682.
145 virtual void NotifyMainFrameSwappedFromRenderManager(
146 RenderViewHost
* old_host
,
147 RenderViewHost
* new_host
) = 0;
148 virtual NavigationControllerImpl
&
149 GetControllerForRenderManager() = 0;
151 // Creates a WebUI object for the given URL if one applies. Ownership of the
152 // returned pointer will be passed to the caller. If no WebUI applies,
154 virtual scoped_ptr
<WebUIImpl
> CreateWebUIForRenderManager(
155 const GURL
& url
) = 0;
157 // Returns the navigation entry of the current navigation, or NULL if there
159 virtual NavigationEntry
*
160 GetLastCommittedNavigationEntryForRenderManager() = 0;
162 // Returns true if the location bar should be focused by default rather than
163 // the page contents. The view calls this function when the tab is focused
164 // to see what it should do.
165 virtual bool FocusLocationBarByDefault() = 0;
167 // Focuses the location bar.
168 virtual void SetFocusToLocationBar(bool select_all
) = 0;
170 // Returns true if views created for this delegate should be created in a
172 virtual bool IsHidden() = 0;
174 // If the delegate is an inner WebContents, this method returns the
175 // FrameTreeNode ID of the frame in the outer WebContents which hosts
176 // the inner WebContents. Returns FrameTreeNode::kFrameTreeNodeInvalidID
177 // if the delegate does not have an outer WebContents.
178 virtual int GetOuterDelegateFrameTreeNodeID() = 0;
181 virtual ~Delegate() {}
184 // Used with FrameTree::ForEach to delete RenderFrameHosts pending shutdown
185 // from a FrameTreeNode's RenderFrameHostManager. Used during destruction of
187 static bool ClearRFHsPendingShutdown(FrameTreeNode
* node
);
189 // Returns true if we are currently in a mode where the swapped out state
190 // should not be used. Currently (as an implementation strategy) swapped out
191 // is forbidden under --site-per-process, but our goal is to eliminate the
192 // mode entirely. In code that deals with the swapped out state, prefer calls
193 // to this function over consulting the switches directly. It will be easier
194 // to grep, and easier to rip out.
196 // TODO(nasko): When swappedout:// is eliminated entirely, this function (and
197 // its equivalent in RenderFrameProxy) should be removed and its callers
199 static bool IsSwappedOutStateForbidden();
201 // All three delegate pointers must be non-NULL and are not owned by this
202 // class. They must outlive this class. The RenderViewHostDelegate and
203 // RenderWidgetHostDelegate are what will be installed into all
204 // RenderViewHosts that are created.
206 // You must call Init() before using this class.
207 RenderFrameHostManager(
208 FrameTreeNode
* frame_tree_node
,
209 RenderFrameHostDelegate
* render_frame_delegate
,
210 RenderViewHostDelegate
* render_view_delegate
,
211 RenderWidgetHostDelegate
* render_widget_delegate
,
213 ~RenderFrameHostManager() override
;
215 // For arguments, see WebContentsImpl constructor.
216 void Init(BrowserContext
* browser_context
,
217 SiteInstance
* site_instance
,
219 int frame_routing_id
);
221 // Returns the currently active RenderFrameHost.
223 // This will be non-NULL between Init() and Shutdown(). You may want to NULL
224 // check it in many cases, however. Windows can send us messages during the
225 // destruction process after it has been shut down.
226 RenderFrameHostImpl
* current_frame_host() const {
227 return render_frame_host_
.get();
230 // TODO(creis): Remove this when we no longer use RVH for navigation.
231 RenderViewHostImpl
* current_host() const;
233 // Returns the view associated with the current RenderViewHost, or NULL if
234 // there is no current one.
235 RenderWidgetHostView
* GetRenderWidgetHostView() const;
237 // Returns whether this manager belongs to a FrameTreeNode that is a main
238 // frame in an inner WebContents.
239 // TODO(lazyboy): Make this work correctly for subframes inside inner
241 bool ForInnerDelegate();
243 // Returns the RenderWidgetHost of the outer WebContents (if any) that can be
244 // used to fetch the last keyboard event.
245 // TODO(lazyboy): This can be removed once input events are sent directly to
247 RenderWidgetHostImpl
* GetOuterRenderWidgetHostForKeyboardInput();
249 RenderFrameProxyHost
* GetProxyToParent();
251 // Returns the proxy to inner WebContents in the outer WebContents's
252 // SiteInstance. Returns nullptr if this WebContents isn't part of inner/outer
254 RenderFrameProxyHost
* GetProxyToOuterDelegate();
256 // Removes the FrameTreeNode in the outer WebContents that represents this
258 // TODO(lazyboy): This does not belong to RenderFrameHostManager, move it to
260 void RemoveOuterDelegateFrame();
262 // Returns the pending RenderFrameHost, or NULL if there is no pending one.
263 RenderFrameHostImpl
* pending_frame_host() const {
264 return pending_render_frame_host_
.get();
267 // Returns the speculative RenderFrameHost, or null if there is no speculative
269 RenderFrameHostImpl
* speculative_frame_host_for_testing() const {
270 return speculative_render_frame_host_
.get();
273 // TODO(creis): Remove this when we no longer use RVH for navigation.
274 RenderViewHostImpl
* pending_render_view_host() const;
276 // Returns the current committed Web UI or NULL if none applies.
277 WebUIImpl
* web_ui() const { return web_ui_
.get(); }
279 // Returns the Web UI for the pending navigation, or NULL of none applies.
280 WebUIImpl
* pending_web_ui() const {
281 return pending_web_ui_
.get() ? pending_web_ui_
.get() :
282 pending_and_current_web_ui_
.get();
286 // Returns the speculative WebUI for the navigation (a newly created one or
287 // the current one if it should be reused). If none is set returns nullptr.
288 WebUIImpl
* speculative_web_ui() const {
289 return should_reuse_web_ui_
? web_ui_
.get() : speculative_web_ui_
.get();
292 // Called when we want to instruct the renderer to navigate to the given
293 // navigation entry. It may create a new RenderFrameHost or re-use an existing
294 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one
295 // could not be created.
296 RenderFrameHostImpl
* Navigate(const FrameNavigationEntry
& frame_entry
,
297 const NavigationEntryImpl
& entry
);
299 // Instructs the various live views to stop. Called when the user directed the
300 // page to stop loading.
303 // Notifies the regular and pending RenderViewHosts that a load is or is not
304 // happening. Even though the message is only for one of them, we don't know
305 // which one so we tell both.
306 void SetIsLoading(bool is_loading
);
308 // Whether to close the tab or not when there is a hang during an unload
309 // handler. If we are mid-crosssite navigation, then we should proceed
310 // with the navigation instead of closing the tab.
311 bool ShouldCloseTabOnUnresponsiveRenderer();
313 // Confirms whether we should close the page or navigate away. This is called
314 // before a cross-site request or before a tab/window is closed (as indicated
315 // by the first parameter) to allow the appropriate renderer to approve or
316 // deny the request. |proceed| indicates whether the user chose to proceed.
317 // |proceed_time| is the time when the request was allowed to proceed.
318 void OnBeforeUnloadACK(bool for_cross_site_transition
,
320 const base::TimeTicks
& proceed_time
);
322 // The |pending_render_frame_host| is ready to commit a page. We should
323 // ensure that the old RenderFrameHost runs its unload handler first and
324 // determine whether a RenderFrameHost transfer is needed.
325 // |cross_site_transferring_request| is NULL if a request is not being
326 // transferred between renderers.
327 void OnCrossSiteResponse(
328 RenderFrameHostImpl
* pending_render_frame_host
,
329 const GlobalRequestID
& global_request_id
,
330 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request
,
331 const std::vector
<GURL
>& transfer_url_chain
,
332 const Referrer
& referrer
,
333 ui::PageTransition page_transition
,
334 bool should_replace_current_entry
);
336 // Called when a renderer's frame navigates.
337 void DidNavigateFrame(RenderFrameHostImpl
* render_frame_host
,
338 bool was_caused_by_user_gesture
);
340 // Called when a renderer sets its opener to null.
341 void DidDisownOpener(RenderFrameHost
* render_frame_host
);
343 // Sets the pending Web UI for the pending navigation, ensuring that the
344 // bindings are appropriate compared to |bindings|.
345 void SetPendingWebUI(const GURL
& url
, int bindings
);
347 // Creates and initializes a RenderFrameHost. The |web_ui| is an optional
348 // input parameter used to double check bindings when swapping back in a
349 // previously existing RenderFrameHost. If |flags| has the
350 // CREATE_RF_SWAPPED_OUT bit set from the CreateRenderFrameFlags enum, it will
351 // initially be placed on the swapped out hosts list. If |view_routing_id_ptr|
352 // is not nullptr it will be set to the routing id of the view associated with
354 scoped_ptr
<RenderFrameHostImpl
> CreateRenderFrame(SiteInstance
* instance
,
358 int* view_routing_id_ptr
);
360 // Helper method to create and initialize a RenderFrameProxyHost and return
362 int CreateRenderFrameProxy(SiteInstance
* instance
);
364 // Creates proxies for a new child frame at FrameTreeNode |child| in all
365 // SiteInstances for which the current frame has proxies. This method is
366 // called on the parent of a new child frame before the child leaves the
368 void CreateProxiesForChildFrame(FrameTreeNode
* child
);
370 // Sets the passed passed interstitial as the currently showing interstitial.
371 // |interstitial_page| should be non NULL (use the remove_interstitial_page
372 // method to unset the interstitial) and no interstitial page should be set
373 // when there is already a non NULL interstitial page set.
374 void set_interstitial_page(InterstitialPageImpl
* interstitial_page
) {
375 DCHECK(!interstitial_page_
&& interstitial_page
);
376 interstitial_page_
= interstitial_page
;
379 // Unsets the currently showing interstitial.
380 void remove_interstitial_page() {
381 DCHECK(interstitial_page_
);
382 interstitial_page_
= NULL
;
385 // Returns the currently showing interstitial, NULL if no interstitial is
387 InterstitialPageImpl
* interstitial_page() const { return interstitial_page_
; }
389 // NotificationObserver implementation.
390 void Observe(int type
,
391 const NotificationSource
& source
,
392 const NotificationDetails
& details
) override
;
394 // Returns whether the given RenderFrameHost (or its associated
395 // RenderViewHost) is on the list of swapped out RenderFrameHosts.
396 bool IsRVHOnSwappedOutList(RenderViewHostImpl
* rvh
) const;
397 bool IsOnSwappedOutList(RenderFrameHostImpl
* rfh
) const;
399 // Returns the swapped out RenderViewHost or RenderFrameHost for the given
400 // SiteInstance, if any. This method is *deprecated* and
401 // GetRenderFrameProxyHost should be used.
402 RenderViewHostImpl
* GetSwappedOutRenderViewHost(SiteInstance
* instance
) const;
403 RenderFrameProxyHost
* GetRenderFrameProxyHost(
404 SiteInstance
* instance
) const;
406 // Returns whether |render_frame_host| is on the pending deletion list.
407 bool IsPendingDeletion(RenderFrameHostImpl
* render_frame_host
);
409 // If |render_frame_host| is on the pending deletion list, this deletes it.
410 // Returns whether it was deleted.
411 bool DeleteFromPendingList(RenderFrameHostImpl
* render_frame_host
);
413 // Deletes any proxy hosts associated with this node. Used during destruction
414 // of WebContentsImpl.
415 void ResetProxyHosts();
417 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy
418 // that has the given SiteInstance and is associated with this
419 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found.
420 int GetRoutingIdForSiteInstance(SiteInstance
* site_instance
);
423 // Notifies the RenderFrameHostManager that a new NavigationRequest has been
424 // created and set in the FrameTreeNode so that it can speculatively create a
425 // new RenderFrameHost (and potentially a new process) if needed.
426 void DidCreateNavigationRequest(const NavigationRequest
& request
);
429 // Called (possibly several times) during a navigation to select or create an
430 // appropriate RenderFrameHost for the provided URL. The returned pointer will
431 // be for the current or the speculative RenderFrameHost and the instance is
432 // owned by this manager.
433 RenderFrameHostImpl
* GetFrameHostForNavigation(
434 const NavigationRequest
& request
);
437 // Clean up any state for any ongoing navigation.
438 void CleanUpNavigation();
441 // Clears the speculative members, returning the RenderFrameHost to the caller
443 scoped_ptr
<RenderFrameHostImpl
> UnsetSpeculativeRenderFrameHost();
445 // Notification methods to tell this RenderFrameHostManager that the frame it
446 // is responsible for has started or stopped loading a document.
447 void OnDidStartLoading();
448 void OnDidStopLoading();
450 // Send updated frame name to all frame proxies when the frame changes its
451 // window.name property.
452 void OnDidUpdateName(const std::string
& name
);
454 // Send updated origin to all frame proxies when the frame navigates to a new
456 void OnDidUpdateOrigin(const url::Origin
& origin
);
458 void EnsureRenderViewInitialized(RenderViewHostImpl
* render_view_host
,
459 SiteInstance
* instance
);
461 // Recursively creates swapped out RenderViews and RenderFrameProxies for
462 // this frame's FrameTree and for its opener chain in the given SiteInstance.
463 // This allows other tabs to send cross-process JavaScript calls to their
464 // opener(s) and to any other frames in the opener's FrameTree (e.g.,
465 // supporting calls like window.opener.opener.frames[x][y]). Returns the
466 // route ID of this frame's RenderView for |instance|.
467 // TODO(alexmos): Switch this to return RenderFrame routing IDs.
468 int CreateOpenerProxies(SiteInstance
* instance
);
470 // Called on the RFHM of the inner WebContents to create a
471 // RenderFrameProxyHost in its outer WebContents's SiteInstance,
472 // |outer_contents_site_instance|. The frame in outer WebContents that is
473 // hosting the inner WebContents is |render_frame_host|, and the frame will
474 // be swapped out with the proxy.
475 void CreateOuterDelegateProxy(SiteInstance
* outer_contents_site_instance
,
476 RenderFrameHostImpl
* render_frame_host
);
478 // Sets the child RenderWidgetHostView for this frame, which must be part of
479 // an inner WebContents.
480 void SetRWHViewForInnerContents(RenderWidgetHostView
* child_rwhv
);
483 friend class FrameTreeVisualizer
;
484 friend class NavigatorTestWithBrowserSideNavigation
;
485 friend class RenderFrameHostManagerTest
;
486 friend class TestWebContents
;
488 // Stores information regarding a SiteInstance targeted at a specific URL to
489 // allow for comparisons without having to actually create new instances. It
490 // can point to an existing one or store the details needed to create a new
492 struct CONTENT_EXPORT SiteInstanceDescriptor
{
493 explicit SiteInstanceDescriptor(content::SiteInstance
* site_instance
)
494 : existing_site_instance(site_instance
),
495 new_is_related_to_current(false) {}
497 SiteInstanceDescriptor(BrowserContext
* browser_context
,
499 bool related_to_current
);
501 // Set with an existing SiteInstance to be reused.
502 content::SiteInstance
* existing_site_instance
;
504 // In case |existing_site_instance| is null, specify a new site URL.
507 // In case |existing_site_instance| is null, specify if the new site should
508 // be created in a new BrowsingInstance or not.
509 bool new_is_related_to_current
;
512 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a
513 // FrameTreeNode's RenderFrameHostManager.
514 static bool ClearProxiesInSiteInstance(int32 site_instance_id
,
515 FrameTreeNode
* node
);
516 // Used with FrameTree::ForEach to reset initialized state of
517 // RenderFrameProxyHosts from a FrameTreeNode's RenderFrameHostManager.
518 static bool ResetProxiesInSiteInstance(int32 site_instance_id
,
519 FrameTreeNode
* node
);
521 // Returns whether this tab should transition to a new renderer for
522 // cross-site URLs. Enabled unless we see the --process-per-tab command line
523 // switch. Can be overridden in unit tests.
524 bool ShouldTransitionCrossSite();
526 // Returns true if for the navigation from |current_effective_url| to
527 // |new_effective_url|, a new SiteInstance and BrowsingInstance should be
528 // created (even if we are in a process model that doesn't usually swap).
529 // This forces a process swap and severs script connections with existing
530 // tabs. Cases where this can happen include transitions between WebUI and
531 // regular web pages. |new_site_instance| may be null.
532 // If there is no current NavigationEntry, then |current_is_view_source_mode|
533 // should be the same as |new_is_view_source_mode|.
535 // We use the effective URL here, since that's what is used in the
536 // SiteInstance's site and when we later call IsSameWebSite. If there is no
537 // current NavigationEntry, check the current SiteInstance's site, which might
538 // already be committed to a Web UI URL (such as the NTP).
539 bool ShouldSwapBrowsingInstancesForNavigation(
540 const GURL
& current_effective_url
,
541 bool current_is_view_source_mode
,
542 SiteInstance
* new_site_instance
,
543 const GURL
& new_effective_url
,
544 bool new_is_view_source_mode
) const;
546 // Creates a new Web UI, ensuring that the bindings are appropriate compared
548 scoped_ptr
<WebUIImpl
> CreateWebUI(const GURL
& url
, int bindings
);
550 // Returns true if it is safe to reuse the current WebUI when navigating from
551 // |current_entry| to |new_url|.
552 bool ShouldReuseWebUI(
553 const NavigationEntry
* current_entry
,
554 const GURL
& new_url
) const;
556 // Returns the SiteInstance to use for the navigation.
557 SiteInstance
* GetSiteInstanceForNavigation(const GURL
& dest_url
,
558 SiteInstance
* source_instance
,
559 SiteInstance
* dest_instance
,
560 SiteInstance
* candidate_instance
,
561 ui::PageTransition transition
,
562 bool dest_is_restore
,
563 bool dest_is_view_source_mode
);
565 // Returns a descriptor of the appropriate SiteInstance object for the given
566 // |dest_url|, possibly reusing the current, source or destination
567 // SiteInstance. The actual SiteInstance can then be obtained calling
568 // ConvertToSiteInstance with the descriptor.
570 // |source_instance| is the SiteInstance of the frame that initiated the
571 // navigation. |current_instance| is the SiteInstance of the frame that is
572 // currently navigating. |dest_instance| is a predetermined SiteInstance that
573 // will be used if not null.
574 // For example, if you have a parent frame A, which has a child frame B, and
575 // A is trying to change the src attribute of B, this will cause a navigation
576 // where the source SiteInstance is A and B is the current SiteInstance.
578 // This is a helper function for GetSiteInstanceForNavigation.
579 SiteInstanceDescriptor
DetermineSiteInstanceForURL(
580 const GURL
& dest_url
,
581 SiteInstance
* source_instance
,
582 SiteInstance
* current_instance
,
583 SiteInstance
* dest_instance
,
584 ui::PageTransition transition
,
585 bool dest_is_restore
,
586 bool dest_is_view_source_mode
,
587 bool force_browsing_instance_swap
);
589 // Converts a SiteInstanceDescriptor to the actual SiteInstance it describes.
590 // If a |candidate_instance| is provided (is not nullptr) and it matches the
591 // description, it is returned as is.
592 SiteInstance
* ConvertToSiteInstance(const SiteInstanceDescriptor
& descriptor
,
593 SiteInstance
* candidate_instance
);
595 // Determines the appropriate url to use as the current url for SiteInstance
597 const GURL
& GetCurrentURLForSiteInstance(
598 SiteInstance
* current_instance
,
599 NavigationEntry
* current_entry
);
601 // Creates a new RenderFrameHostImpl for the |new_instance| and assign it to
602 // |pending_render_frame_host_| while respecting the opener route if needed
603 // and stores it in pending_render_frame_host_.
604 void CreatePendingRenderFrameHost(SiteInstance
* old_instance
,
605 SiteInstance
* new_instance
,
608 // Ensure that we have created all needed proxies for a new RFH with
609 // SiteInstance |new_instance|: (1) create swapped-out RVHs and proxies for
610 // the new RFH's opener chain if we are staying in the same BrowsingInstance;
611 // (2) Create proxies for the new RFH's SiteInstance in its own frame tree;
612 // (3) set any additional flags for the new RenderFrame with
613 // |create_render_frame_flags|.
614 // Returns the opener's RVH route ID to be used for the new RenderFrame.
615 // TODO(alexmos): switch this to return opener's RFH routing ID instead.
616 int CreateProxiesForNewRenderFrameHost(SiteInstance
* old_instance
,
617 SiteInstance
* new_instance
,
618 int* create_render_frame_flags
);
620 // Create swapped out RenderViews and RenderFrameProxies in the given
621 // SiteInstance for all frames on the opener chain of this frame. Same as
622 // CreateOpenerProxies, but starts from this frame's opener, returning
623 // MSG_ROUTING_NONE if it doesn't exist, and calling CreateOpenerProxies if
625 // TODO(alexmos): Switch this to return RenderFrame routing IDs.
626 int CreateOpenerProxiesIfNeeded(SiteInstance
* instance
);
628 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
629 scoped_ptr
<RenderFrameHostImpl
> CreateRenderFrameHost(SiteInstance
* instance
,
631 int frame_routing_id
,
635 // Creates and initializes a speculative RenderFrameHost and/or WebUI for an
636 // ongoing navigation. They might be destroyed and re-created later if the
637 // navigation is redirected to a different SiteInstance.
638 bool CreateSpeculativeRenderFrameHost(const GURL
& url
,
639 SiteInstance
* old_instance
,
640 SiteInstance
* new_instance
,
643 // Sets up the necessary state for a new RenderViewHost with the given opener,
644 // if necessary. It creates a RenderFrameProxy in the target renderer process
645 // with the given |proxy_routing_id|, which is used to route IPC messages when
646 // in swapped out state. Returns early if the RenderViewHost has already been
647 // initialized for another RenderFrameHost.
648 // TODO(creis): opener_route_id is currently for the RenderViewHost but should
649 // be for the RenderFrame, since frames can have openers.
650 bool InitRenderView(RenderViewHostImpl
* render_view_host
,
652 int proxy_routing_id
,
653 bool for_main_frame_navigation
);
655 // Initialization for RenderFrameHost uses the same sequence as InitRenderView
657 bool InitRenderFrame(RenderFrameHostImpl
* render_frame_host
);
659 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
660 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
661 // since there could be Web UI switching as well. Call this for every commit.
662 // If PlzNavigate is enabled the method will set the speculative (not pending)
663 // RenderFrameHost to be the active one.
664 void CommitPending();
666 // Helper to call CommitPending() in all necessary cases.
667 void CommitPendingIfNecessary(RenderFrameHostImpl
* render_frame_host
,
668 bool was_caused_by_user_gesture
);
670 // Commits any pending sandbox flag updates when the renderer's frame
672 void CommitPendingSandboxFlags();
674 // Runs the unload handler in the old RenderFrameHost, after the new
675 // RenderFrameHost has committed. |old_render_frame_host| will either be
676 // deleted or put on the pending delete list during this call.
677 void SwapOutOldFrame(scoped_ptr
<RenderFrameHostImpl
> old_render_frame_host
);
679 // Discards a RenderFrameHost that was never made active (for active ones
680 // SwapOutOldFrame is used instead).
681 void DiscardUnusedFrame(scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
683 // Holds |render_frame_host| until it can be deleted when its swap out ACK
685 void MoveToPendingDeleteHosts(
686 scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
688 // If |render_frame_host| is the last remaining active frame in its
689 // SiteInstance, this will shutdown all the RenderFrameProxyHosts in the
690 // SiteInstance. This is appropriate if |render_frame_host| is about to be
692 void ShutdownProxiesIfLastActiveFrameInSiteInstance(
693 RenderFrameHostImpl
* render_frame_host
);
695 // Helper method to terminate the pending RenderFrameHost. The frame may be
696 // deleted immediately, or it may be kept around in hopes of later reuse.
697 void CancelPending();
699 // Clears pending_render_frame_host_, returning it to the caller for disposal.
700 scoped_ptr
<RenderFrameHostImpl
> UnsetPendingRenderFrameHost();
702 // Helper method to set the active RenderFrameHost. Returns the old
703 // RenderFrameHost and updates counts.
704 scoped_ptr
<RenderFrameHostImpl
> SetRenderFrameHost(
705 scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
707 RenderFrameHostImpl
* UpdateStateForNavigate(
708 const GURL
& dest_url
,
709 SiteInstance
* source_instance
,
710 SiteInstance
* dest_instance
,
711 ui::PageTransition transition
,
712 bool dest_is_restore
,
713 bool dest_is_view_source_mode
,
714 const GlobalRequestID
& transferred_request_id
,
717 // Called when a renderer process is starting to close. We should not
718 // schedule new navigations in its swapped out RenderFrameHosts after this.
719 void RendererProcessClosing(RenderProcessHost
* render_process_host
);
721 // Helper method to delete a RenderFrameProxyHost from the list, if one exists
722 // for the given |instance|.
723 void DeleteRenderFrameProxyHost(SiteInstance
* instance
);
725 // For use in creating RenderFrameHosts.
726 FrameTreeNode
* frame_tree_node_
;
728 // Our delegate, not owned by us. Guaranteed non-NULL.
731 // Implemented by the owner of this class. These delegates are installed into
732 // all the RenderFrameHosts that we create.
733 RenderFrameHostDelegate
* render_frame_delegate_
;
734 RenderViewHostDelegate
* render_view_delegate_
;
735 RenderWidgetHostDelegate
* render_widget_delegate_
;
737 // Our RenderFrameHost and its associated Web UI (if any, will be NULL for
738 // non-WebUI pages). This object is responsible for all communication with
739 // a child RenderFrame instance.
740 // For now, RenderFrameHost keeps a RenderViewHost in its SiteInstance alive.
741 // Eventually, RenderViewHost will be replaced with a page context.
742 scoped_ptr
<RenderFrameHostImpl
> render_frame_host_
;
743 scoped_ptr
<WebUIImpl
> web_ui_
;
745 // A RenderFrameHost used to load a cross-site page. This remains hidden
746 // while a cross-site request is pending until it calls DidNavigate. It may
747 // have an associated Web UI, in which case the Web UI pointer will be non-
750 // The |pending_web_ui_| may be non-NULL even when the
751 // |pending_render_frame_host_| is NULL. This will happen when we're
752 // transitioning between two Web UI pages: the RFH won't be swapped, so the
753 // pending pointer will be unused, but there will be a pending Web UI
754 // associated with the navigation.
755 // Note: This is not used in PlzNavigate.
756 scoped_ptr
<RenderFrameHostImpl
> pending_render_frame_host_
;
758 // If a pending request needs to be transferred to another process, this
759 // owns the request until it's transferred to the new process, so it will be
760 // cleaned up if the navigation is cancelled. Otherwise, this is NULL.
761 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request_
;
763 // If either of these is non-NULL, the pending navigation is to a chrome:
764 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is
765 // used for when they reference the same object. If either is non-NULL, the
766 // other should be NULL.
767 // Note: These are not used in PlzNavigate.
768 scoped_ptr
<WebUIImpl
> pending_web_ui_
;
769 base::WeakPtr
<WebUIImpl
> pending_and_current_web_ui_
;
771 // A map of site instance ID to RenderFrameProxyHosts.
772 typedef base::hash_map
<int32
, RenderFrameProxyHost
*> RenderFrameProxyHostMap
;
773 RenderFrameProxyHostMap proxy_hosts_
;
775 // A list of RenderFrameHosts waiting to shut down after swapping out. We use
776 // a linked list since we expect frequent deletes and no indexed access, and
777 // because sets don't appear to support linked_ptrs.
778 typedef std::list
<linked_ptr
<RenderFrameHostImpl
> > RFHPendingDeleteList
;
779 RFHPendingDeleteList pending_delete_hosts_
;
781 // The intersitial page currently shown if any, not own by this class
782 // (the InterstitialPage is self-owned, it deletes itself when hidden).
783 InterstitialPageImpl
* interstitial_page_
;
785 NotificationRegistrar registrar_
;
788 // These members store a speculative RenderFrameHost and WebUI. They are
789 // created early in a navigation so a renderer process can be started in
790 // parallel, if needed. This is purely a performance optimization and is not
791 // required for correct behavior. The created RenderFrameHost might be
792 // discarded later on if the final URL's SiteInstance isn't compatible with
793 // what was used to create it.
794 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not
796 scoped_ptr
<RenderFrameHostImpl
> speculative_render_frame_host_
;
797 scoped_ptr
<WebUIImpl
> speculative_web_ui_
;
800 // If true at navigation commit time the current WebUI will be kept instead of
801 // creating a new one.
802 bool should_reuse_web_ui_
;
804 base::WeakPtrFactory
<RenderFrameHostManager
> weak_factory_
;
806 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager
);
809 } // namespace content
811 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_