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_
11 #include "base/basictypes.h"
12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "content/browser/renderer_host/render_view_host_delegate.h"
16 #include "content/browser/site_instance_impl.h"
17 #include "content/common/content_export.h"
18 #include "content/public/browser/global_request_id.h"
19 #include "content/public/common/referrer.h"
20 #include "ui/base/page_transition_types.h"
21 #include "url/origin.h"
25 class CrossProcessFrameConnector
;
26 class CrossSiteTransferringRequest
;
27 class FrameNavigationEntry
;
29 class InterstitialPageImpl
;
30 class NavigationControllerImpl
;
31 class NavigationEntry
;
32 class NavigationEntryImpl
;
33 class NavigationHandleImpl
;
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
{
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.
120 virtual bool CreateRenderViewForRenderManager(
121 RenderViewHost
* render_view_host
,
122 int opener_frame_routing_id
,
123 int proxy_routing_id
,
124 const FrameReplicationState
& replicated_frame_state
) = 0;
125 virtual void CreateRenderWidgetHostViewForRenderManager(
126 RenderViewHost
* render_view_host
) = 0;
127 virtual bool CreateRenderFrameForRenderManager(
128 RenderFrameHost
* render_frame_host
,
129 int proxy_routing_id
,
130 int opener_routing_id
,
131 int parent_routing_id
,
132 int previous_sibling_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 // All three delegate pointers must be non-NULL and are not owned by this
190 // class. They must outlive this class. The RenderViewHostDelegate and
191 // RenderWidgetHostDelegate are what will be installed into all
192 // RenderViewHosts that are created.
194 // You must call Init() before using this class.
195 RenderFrameHostManager(
196 FrameTreeNode
* frame_tree_node
,
197 RenderFrameHostDelegate
* render_frame_delegate
,
198 RenderViewHostDelegate
* render_view_delegate
,
199 RenderWidgetHostDelegate
* render_widget_delegate
,
201 ~RenderFrameHostManager();
203 // For arguments, see WebContentsImpl constructor.
204 void Init(BrowserContext
* browser_context
,
205 SiteInstance
* site_instance
,
206 int32 view_routing_id
,
207 int32 frame_routing_id
,
208 int32 widget_routing_id
,
211 // Returns the currently active RenderFrameHost.
213 // This will be non-NULL between Init() and Shutdown(). You may want to NULL
214 // check it in many cases, however. Windows can send us messages during the
215 // destruction process after it has been shut down.
216 RenderFrameHostImpl
* current_frame_host() const {
217 return render_frame_host_
.get();
220 // TODO(creis): Remove this when we no longer use RVH for navigation.
221 RenderViewHostImpl
* current_host() const;
223 // Returns the view associated with the current RenderViewHost, or NULL if
224 // there is no current one.
225 RenderWidgetHostView
* GetRenderWidgetHostView() const;
227 // Returns whether this manager belongs to a FrameTreeNode that belongs to an
228 // inner WebContents.
229 bool ForInnerDelegate();
231 // Returns the RenderWidgetHost of the outer WebContents (if any) that can be
232 // used to fetch the last keyboard event.
233 // TODO(lazyboy): This can be removed once input events are sent directly to
235 RenderWidgetHostImpl
* GetOuterRenderWidgetHostForKeyboardInput();
237 RenderFrameProxyHost
* GetProxyToParent();
239 // Returns the proxy to inner WebContents in the outer WebContents's
240 // SiteInstance. Returns nullptr if this WebContents isn't part of inner/outer
242 RenderFrameProxyHost
* GetProxyToOuterDelegate();
244 // Removes the FrameTreeNode in the outer WebContents that represents this
246 // TODO(lazyboy): This does not belong to RenderFrameHostManager, move it to
248 void RemoveOuterDelegateFrame();
250 // Returns the pending RenderFrameHost, or NULL if there is no pending one.
251 RenderFrameHostImpl
* pending_frame_host() const {
252 return pending_render_frame_host_
.get();
255 // Returns the speculative RenderFrameHost, or null if there is no speculative
257 RenderFrameHostImpl
* speculative_frame_host() const {
258 return speculative_render_frame_host_
.get();
261 // TODO(creis): Remove this when we no longer use RVH for navigation.
262 RenderViewHostImpl
* pending_render_view_host() const;
264 // Returns the current committed Web UI or NULL if none applies.
265 WebUIImpl
* web_ui() const { return web_ui_
.get(); }
267 // Returns the Web UI for the pending navigation, or NULL of none applies.
268 WebUIImpl
* pending_web_ui() const {
269 return pending_web_ui_
.get() ? pending_web_ui_
.get() :
270 pending_and_current_web_ui_
.get();
274 // Returns the speculative WebUI for the navigation (a newly created one or
275 // the current one if it should be reused). If none is set returns nullptr.
276 WebUIImpl
* speculative_web_ui() const {
277 return should_reuse_web_ui_
? web_ui_
.get() : speculative_web_ui_
.get();
280 // Called when we want to instruct the renderer to navigate to the given
281 // navigation entry. It may create a new RenderFrameHost or re-use an existing
282 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one
283 // could not be created. |dest_url| takes precedence over the |frame_entry|'s
284 // url (this is necessary because ReloadOriginalRequest navigates to a
285 // different URL than the last committed entry, without modifying it).
286 RenderFrameHostImpl
* Navigate(const GURL
& dest_url
,
287 const FrameNavigationEntry
& frame_entry
,
288 const NavigationEntryImpl
& entry
);
290 // Instructs the various live views to stop. Called when the user directed the
291 // page to stop loading.
294 // Notifies the regular and pending RenderViewHosts that a load is or is not
295 // happening. Even though the message is only for one of them, we don't know
296 // which one so we tell both.
297 void SetIsLoading(bool is_loading
);
299 // Whether to close the tab or not when there is a hang during an unload
300 // handler. If we are mid-crosssite navigation, then we should proceed
301 // with the navigation instead of closing the tab.
302 bool ShouldCloseTabOnUnresponsiveRenderer();
304 // Confirms whether we should close the page or navigate away. This is called
305 // before a cross-site request or before a tab/window is closed (as indicated
306 // by the first parameter) to allow the appropriate renderer to approve or
307 // deny the request. |proceed| indicates whether the user chose to proceed.
308 // |proceed_time| is the time when the request was allowed to proceed.
309 void OnBeforeUnloadACK(bool for_cross_site_transition
,
311 const base::TimeTicks
& proceed_time
);
313 // The |pending_render_frame_host| is ready to commit a page. We should
314 // ensure that the old RenderFrameHost runs its unload handler first and
315 // determine whether a RenderFrameHost transfer is needed.
316 // |cross_site_transferring_request| is NULL if a request is not being
317 // transferred between renderers.
318 void OnCrossSiteResponse(
319 RenderFrameHostImpl
* pending_render_frame_host
,
320 const GlobalRequestID
& global_request_id
,
321 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request
,
322 const std::vector
<GURL
>& transfer_url_chain
,
323 const Referrer
& referrer
,
324 ui::PageTransition page_transition
,
325 bool should_replace_current_entry
);
327 // Called when a renderer's frame navigates.
328 void DidNavigateFrame(RenderFrameHostImpl
* render_frame_host
,
329 bool was_caused_by_user_gesture
);
331 // Called when this frame's opener is changed to the frame specified by
332 // |opener_routing_id| in |source_site_instance|'s process. This change
333 // could come from either the current RenderFrameHost or one of the
334 // proxies (e.g., window.open that targets a RemoteFrame by name). The
335 // updated opener will be forwarded to any other RenderFrameProxies and
336 // RenderFrames for this FrameTreeNode.
337 void DidChangeOpener(int opener_routing_id
,
338 SiteInstance
* source_site_instance
);
340 // Sets the pending Web UI for the pending navigation, ensuring that the
341 // bindings are appropriate compared to |bindings|.
342 void SetPendingWebUI(const GURL
& url
, int bindings
);
344 // Creates and initializes a RenderFrameHost. The |web_ui| is an optional
345 // input parameter used to double check bindings when swapping back in a
346 // previously existing RenderFrameHost. If |flags| has the
347 // CREATE_RF_SWAPPED_OUT bit set from the CreateRenderFrameFlags enum, it will
348 // initially be placed on the swapped out hosts list. If |view_routing_id_ptr|
349 // is not nullptr it will be set to the routing id of the view associated with
351 scoped_ptr
<RenderFrameHostImpl
> CreateRenderFrame(SiteInstance
* instance
,
354 int* view_routing_id_ptr
);
356 // Helper method to create and initialize a RenderFrameProxyHost and return
358 int CreateRenderFrameProxy(SiteInstance
* instance
);
360 // Creates proxies for a new child frame at FrameTreeNode |child| in all
361 // SiteInstances for which the current frame has proxies. This method is
362 // called on the parent of a new child frame before the child leaves the
364 void CreateProxiesForChildFrame(FrameTreeNode
* child
);
366 // Sets the passed passed interstitial as the currently showing interstitial.
367 // |interstitial_page| should be non NULL (use the remove_interstitial_page
368 // method to unset the interstitial) and no interstitial page should be set
369 // when there is already a non NULL interstitial page set.
370 void set_interstitial_page(InterstitialPageImpl
* interstitial_page
) {
371 DCHECK(!interstitial_page_
&& interstitial_page
);
372 interstitial_page_
= interstitial_page
;
375 // Unsets the currently showing interstitial.
376 void remove_interstitial_page() {
377 DCHECK(interstitial_page_
);
378 interstitial_page_
= NULL
;
381 // Returns the currently showing interstitial, NULL if no interstitial is
383 InterstitialPageImpl
* interstitial_page() const { return interstitial_page_
; }
385 // Returns whether the given RenderFrameHost (or its associated
386 // RenderViewHost) is on the list of swapped out RenderFrameHosts.
387 bool IsRVHOnSwappedOutList(RenderViewHostImpl
* rvh
) const;
388 bool IsOnSwappedOutList(RenderFrameHostImpl
* rfh
) const;
390 // Returns the swapped out RenderViewHost for the given SiteInstance, if any.
391 // This method is *deprecated* and GetRenderFrameProxyHost should be used.
392 RenderViewHostImpl
* GetSwappedOutRenderViewHost(SiteInstance
* instance
) const;
394 // Returns the RenderFrameProxyHost for the given SiteInstance, if any.
395 RenderFrameProxyHost
* GetRenderFrameProxyHost(
396 SiteInstance
* instance
) const;
398 // Returns whether |render_frame_host| is on the pending deletion list.
399 bool IsPendingDeletion(RenderFrameHostImpl
* render_frame_host
);
401 // If |render_frame_host| is on the pending deletion list, this deletes it.
402 // Returns whether it was deleted.
403 bool DeleteFromPendingList(RenderFrameHostImpl
* render_frame_host
);
405 // Deletes any proxy hosts associated with this node. Used during destruction
406 // of WebContentsImpl.
407 void ResetProxyHosts();
409 // Returns the routing id for a RenderFrameHost or RenderFrameProxyHost
410 // that has the given SiteInstance and is associated with this
411 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found.
412 int GetRoutingIdForSiteInstance(SiteInstance
* site_instance
);
415 // Notifies the RenderFrameHostManager that a new NavigationRequest has been
416 // created and set in the FrameTreeNode so that it can speculatively create a
417 // new RenderFrameHost (and potentially a new process) if needed.
418 void DidCreateNavigationRequest(const NavigationRequest
& request
);
421 // Called (possibly several times) during a navigation to select or create an
422 // appropriate RenderFrameHost for the provided URL. The returned pointer will
423 // be for the current or the speculative RenderFrameHost and the instance is
424 // owned by this manager.
425 RenderFrameHostImpl
* GetFrameHostForNavigation(
426 const NavigationRequest
& request
);
429 // Clean up any state for any ongoing navigation.
430 void CleanUpNavigation();
433 // Clears the speculative members, returning the RenderFrameHost to the caller
435 scoped_ptr
<RenderFrameHostImpl
> UnsetSpeculativeRenderFrameHost();
437 // Notification methods to tell this RenderFrameHostManager that the frame it
438 // is responsible for has started or stopped loading a document.
439 void OnDidStartLoading();
440 void OnDidStopLoading();
442 // Send updated frame name to all frame proxies when the frame changes its
443 // window.name property.
444 void OnDidUpdateName(const std::string
& name
);
446 // Send updated origin to all frame proxies when the frame navigates to a new
448 void OnDidUpdateOrigin(const url::Origin
& origin
);
450 void EnsureRenderViewInitialized(RenderViewHostImpl
* render_view_host
,
451 SiteInstance
* instance
);
453 // Creates swapped out RenderViews and RenderFrameProxies for this frame's
454 // FrameTree and for its opener chain in the given SiteInstance. This allows
455 // other tabs to send cross-process JavaScript calls to their opener(s) and
456 // to any other frames in the opener's FrameTree (e.g., supporting calls like
457 // window.opener.opener.frames[x][y]). Does not create proxies for the
458 // subtree rooted at |skip_this_node| (e.g., if a node is being navigated, it
459 // can be passed here to prevent proxies from being created for it, in
460 // case it is in the same FrameTree as another node on its opener chain).
461 void CreateOpenerProxies(SiteInstance
* instance
,
462 FrameTreeNode
* skip_this_node
);
464 // Ensure that this frame has proxies in all SiteInstances that can discover
465 // this frame by name (e.g., via window.open("", "frame_name")). See
466 // https://crbug.com/511474.
467 void CreateProxiesForNewNamedFrame();
469 // Returns a routing ID for the current FrameTreeNode's opener node in the
470 // given SiteInstance. May return a routing ID of either a RenderFrameHost
471 // (if opener's current or pending RFH has SiteInstance |instance|) or a
472 // RenderFrameProxyHost. Returns MSG_ROUTING_NONE if there is no opener, or
473 // if the opener node doesn't have a proxy for |instance|.
474 int GetOpenerRoutingID(SiteInstance
* instance
);
476 // Called on the RFHM of the inner WebContents to create a
477 // RenderFrameProxyHost in its outer WebContents's SiteInstance,
478 // |outer_contents_site_instance|. The frame in outer WebContents that is
479 // hosting the inner WebContents is |render_frame_host|, and the frame will
480 // be swapped out with the proxy.
481 void CreateOuterDelegateProxy(SiteInstance
* outer_contents_site_instance
,
482 RenderFrameHostImpl
* render_frame_host
);
484 // Sets the child RenderWidgetHostView for this frame, which must be part of
485 // an inner WebContents.
486 void SetRWHViewForInnerContents(RenderWidgetHostView
* child_rwhv
);
488 // Returns a copy of the map of proxy hosts. The keys are SiteInstance IDs,
489 // the values are RenderFrameProxyHosts.
490 std::map
<int, RenderFrameProxyHost
*> GetAllProxyHostsForTesting();
493 friend class NavigatorTestWithBrowserSideNavigation
;
494 friend class RenderFrameHostManagerTest
;
495 friend class TestWebContents
;
497 // Stores information regarding a SiteInstance targeted at a specific URL to
498 // allow for comparisons without having to actually create new instances. It
499 // can point to an existing one or store the details needed to create a new
501 struct CONTENT_EXPORT SiteInstanceDescriptor
{
502 explicit SiteInstanceDescriptor(content::SiteInstance
* site_instance
)
503 : existing_site_instance(site_instance
),
504 new_is_related_to_current(false) {}
506 SiteInstanceDescriptor(BrowserContext
* browser_context
,
508 bool related_to_current
);
510 // Set with an existing SiteInstance to be reused.
511 content::SiteInstance
* existing_site_instance
;
513 // In case |existing_site_instance| is null, specify a new site URL.
516 // In case |existing_site_instance| is null, specify if the new site should
517 // be created in a new BrowsingInstance or not.
518 bool new_is_related_to_current
;
521 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a
522 // FrameTreeNode's RenderFrameHostManager.
523 static bool ClearProxiesInSiteInstance(int32 site_instance_id
,
524 FrameTreeNode
* node
);
525 // Used with FrameTree::ForEach to reset initialized state of
526 // RenderFrameProxyHosts from a FrameTreeNode's RenderFrameHostManager.
527 static bool ResetProxiesInSiteInstance(int32 site_instance_id
,
528 FrameTreeNode
* node
);
530 // Returns whether this tab should transition to a new renderer for
531 // cross-site URLs. Enabled unless we see the --process-per-tab command line
532 // switch. Can be overridden in unit tests.
533 bool ShouldTransitionCrossSite();
535 // Returns true if for the navigation from |current_effective_url| to
536 // |new_effective_url|, a new SiteInstance and BrowsingInstance should be
537 // created (even if we are in a process model that doesn't usually swap).
538 // This forces a process swap and severs script connections with existing
539 // tabs. Cases where this can happen include transitions between WebUI and
540 // regular web pages. |new_site_instance| may be null.
541 // If there is no current NavigationEntry, then |current_is_view_source_mode|
542 // should be the same as |new_is_view_source_mode|.
544 // We use the effective URL here, since that's what is used in the
545 // SiteInstance's site and when we later call IsSameWebSite. If there is no
546 // current NavigationEntry, check the current SiteInstance's site, which might
547 // already be committed to a Web UI URL (such as the NTP).
548 bool ShouldSwapBrowsingInstancesForNavigation(
549 const GURL
& current_effective_url
,
550 bool current_is_view_source_mode
,
551 SiteInstance
* new_site_instance
,
552 const GURL
& new_effective_url
,
553 bool new_is_view_source_mode
) const;
555 // Creates a new Web UI, ensuring that the bindings are appropriate compared
557 scoped_ptr
<WebUIImpl
> CreateWebUI(const GURL
& url
, int bindings
);
559 // Returns true if it is safe to reuse the current WebUI when navigating from
560 // |current_entry| to |new_url|.
561 bool ShouldReuseWebUI(
562 const NavigationEntry
* current_entry
,
563 const GURL
& new_url
) const;
565 // Returns the SiteInstance to use for the navigation.
566 SiteInstance
* GetSiteInstanceForNavigation(const GURL
& dest_url
,
567 SiteInstance
* source_instance
,
568 SiteInstance
* dest_instance
,
569 SiteInstance
* candidate_instance
,
570 ui::PageTransition transition
,
571 bool dest_is_restore
,
572 bool dest_is_view_source_mode
);
574 // Returns a descriptor of the appropriate SiteInstance object for the given
575 // |dest_url|, possibly reusing the current, source or destination
576 // SiteInstance. The actual SiteInstance can then be obtained calling
577 // ConvertToSiteInstance with the descriptor.
579 // |source_instance| is the SiteInstance of the frame that initiated the
580 // navigation. |current_instance| is the SiteInstance of the frame that is
581 // currently navigating. |dest_instance| is a predetermined SiteInstance that
582 // will be used if not null.
583 // For example, if you have a parent frame A, which has a child frame B, and
584 // A is trying to change the src attribute of B, this will cause a navigation
585 // where the source SiteInstance is A and B is the current SiteInstance.
587 // This is a helper function for GetSiteInstanceForNavigation.
588 SiteInstanceDescriptor
DetermineSiteInstanceForURL(
589 const GURL
& dest_url
,
590 SiteInstance
* source_instance
,
591 SiteInstance
* current_instance
,
592 SiteInstance
* dest_instance
,
593 ui::PageTransition transition
,
594 bool dest_is_restore
,
595 bool dest_is_view_source_mode
,
596 bool force_browsing_instance_swap
);
598 // Converts a SiteInstanceDescriptor to the actual SiteInstance it describes.
599 // If a |candidate_instance| is provided (is not nullptr) and it matches the
600 // description, it is returned as is.
601 SiteInstance
* ConvertToSiteInstance(const SiteInstanceDescriptor
& descriptor
,
602 SiteInstance
* candidate_instance
);
604 // Determines the appropriate url to use as the current url for SiteInstance
606 const GURL
& GetCurrentURLForSiteInstance(
607 SiteInstance
* current_instance
,
608 NavigationEntry
* current_entry
);
610 // Creates a new RenderFrameHostImpl for the |new_instance| and assign it to
611 // |pending_render_frame_host_| while respecting the opener route if needed
612 // and stores it in pending_render_frame_host_.
613 void CreatePendingRenderFrameHost(SiteInstance
* old_instance
,
614 SiteInstance
* new_instance
);
616 // Ensure that we have created all needed proxies for a new RFH with
617 // SiteInstance |new_instance|: (1) create swapped-out RVHs and proxies for
618 // the new RFH's opener chain if we are staying in the same BrowsingInstance;
619 // (2) Create proxies for the new RFH's SiteInstance in its own frame tree.
620 void CreateProxiesForNewRenderFrameHost(SiteInstance
* old_instance
,
621 SiteInstance
* new_instance
);
623 // Traverse the opener chain and populate |opener_frame_trees| with
624 // all FrameTrees accessible by following frame openers of nodes in the
625 // given node's FrameTree. |opener_frame_trees| is ordered so that openers
626 // of smaller-indexed entries point to larger-indexed entries (i.e., this
627 // node's FrameTree is at index 0, its opener's FrameTree is at index 1,
628 // etc). If the traversal encounters a node with an opener pointing to a
629 // FrameTree that has already been traversed (such as when there's a cycle),
630 // the node is added to |nodes_with_back_links|.
631 void CollectOpenerFrameTrees(
632 std::vector
<FrameTree
*>* opener_frame_trees
,
633 base::hash_set
<FrameTreeNode
*>* nodes_with_back_links
);
635 // Create swapped out RenderViews and RenderFrameProxies in the given
636 // SiteInstance for the current node's FrameTree. Used as a helper function
637 // in CreateOpenerProxies for creating proxies in each FrameTree on the
638 // opener chain. Don't create proxies for the subtree rooted at
640 void CreateOpenerProxiesForFrameTree(SiteInstance
* instance
,
641 FrameTreeNode
* skip_this_node
);
643 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
644 scoped_ptr
<RenderFrameHostImpl
> CreateRenderFrameHost(SiteInstance
* instance
,
645 int32 view_routing_id
,
646 int32 frame_routing_id
,
647 int32 widget_routing_id
,
652 // Creates and initializes a speculative RenderFrameHost and/or WebUI for an
653 // ongoing navigation. They might be destroyed and re-created later if the
654 // navigation is redirected to a different SiteInstance.
655 bool CreateSpeculativeRenderFrameHost(const GURL
& url
,
656 SiteInstance
* old_instance
,
657 SiteInstance
* new_instance
,
660 // Sets up the necessary state for a new RenderViewHost. Creates a
661 // RenderFrameProxy in the target renderer process with the given
662 // |proxy_routing_id|, which is used to route IPC messages when in swapped
663 // out state. Returns early if the RenderViewHost has already been
664 // initialized for another RenderFrameHost.
665 bool InitRenderView(RenderViewHostImpl
* render_view_host
,
666 int proxy_routing_id
);
668 // Initialization for RenderFrameHost uses the same sequence as InitRenderView
670 bool InitRenderFrame(RenderFrameHostImpl
* render_frame_host
);
672 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
673 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
674 // since there could be Web UI switching as well. Call this for every commit.
675 // If PlzNavigate is enabled the method will set the speculative (not pending)
676 // RenderFrameHost to be the active one.
677 void CommitPending();
679 // Helper to call CommitPending() in all necessary cases.
680 void CommitPendingIfNecessary(RenderFrameHostImpl
* render_frame_host
,
681 bool was_caused_by_user_gesture
);
683 // Commits any pending sandbox flag updates when the renderer's frame
685 void CommitPendingSandboxFlags();
687 // Runs the unload handler in the old RenderFrameHost, after the new
688 // RenderFrameHost has committed. |old_render_frame_host| will either be
689 // deleted or put on the pending delete list during this call.
690 void SwapOutOldFrame(scoped_ptr
<RenderFrameHostImpl
> old_render_frame_host
);
692 // Discards a RenderFrameHost that was never made active (for active ones
693 // SwapOutOldFrame is used instead).
694 void DiscardUnusedFrame(scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
696 // Holds |render_frame_host| until it can be deleted when its swap out ACK
698 void MoveToPendingDeleteHosts(
699 scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
701 // If |render_frame_host| is the last remaining active frame in its
702 // SiteInstance, this will shutdown all the RenderFrameProxyHosts in the
703 // SiteInstance. This is appropriate if |render_frame_host| is about to be
705 void ShutdownProxiesIfLastActiveFrameInSiteInstance(
706 RenderFrameHostImpl
* render_frame_host
);
708 // Helper method to terminate the pending RenderFrameHost. The frame may be
709 // deleted immediately, or it may be kept around in hopes of later reuse.
710 void CancelPending();
712 // Clears pending_render_frame_host_, returning it to the caller for disposal.
713 scoped_ptr
<RenderFrameHostImpl
> UnsetPendingRenderFrameHost();
715 // Helper method to set the active RenderFrameHost. Returns the old
716 // RenderFrameHost and updates counts.
717 scoped_ptr
<RenderFrameHostImpl
> SetRenderFrameHost(
718 scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
720 RenderFrameHostImpl
* UpdateStateForNavigate(
721 const GURL
& dest_url
,
722 SiteInstance
* source_instance
,
723 SiteInstance
* dest_instance
,
724 ui::PageTransition transition
,
725 bool dest_is_restore
,
726 bool dest_is_view_source_mode
,
727 const GlobalRequestID
& transferred_request_id
,
730 // Called when a renderer process is starting to close. We should not
731 // schedule new navigations in its swapped out RenderFrameHosts after this.
732 void RendererProcessClosing(RenderProcessHost
* render_process_host
);
734 // For use in creating RenderFrameHosts.
735 FrameTreeNode
* frame_tree_node_
;
737 // Our delegate, not owned by us. Guaranteed non-NULL.
740 // Implemented by the owner of this class. These delegates are installed into
741 // all the RenderFrameHosts that we create.
742 RenderFrameHostDelegate
* render_frame_delegate_
;
743 RenderViewHostDelegate
* render_view_delegate_
;
744 RenderWidgetHostDelegate
* render_widget_delegate_
;
746 // Our RenderFrameHost and its associated Web UI (if any, will be NULL for
747 // non-WebUI pages). This object is responsible for all communication with
748 // a child RenderFrame instance.
749 // For now, RenderFrameHost keeps a RenderViewHost in its SiteInstance alive.
750 // Eventually, RenderViewHost will be replaced with a page context.
751 scoped_ptr
<RenderFrameHostImpl
> render_frame_host_
;
752 scoped_ptr
<WebUIImpl
> web_ui_
;
754 // A RenderFrameHost used to load a cross-site page. This remains hidden
755 // while a cross-site request is pending until it calls DidNavigate. It may
756 // have an associated Web UI, in which case the Web UI pointer will be non-
759 // The |pending_web_ui_| may be non-NULL even when the
760 // |pending_render_frame_host_| is NULL. This will happen when we're
761 // transitioning between two Web UI pages: the RFH won't be swapped, so the
762 // pending pointer will be unused, but there will be a pending Web UI
763 // associated with the navigation.
764 // Note: This is not used in PlzNavigate.
765 scoped_ptr
<RenderFrameHostImpl
> pending_render_frame_host_
;
767 // If a pending request needs to be transferred to another process, this
768 // owns the request until it's transferred to the new process, so it will be
769 // cleaned up if the navigation is cancelled. Otherwise, this is NULL.
770 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request_
;
772 // This is used to temporarily store the NavigationHandle during
773 // transferring navigations. The handle needs to be stored because the old
774 // RenderFrameHost may be discarded before a new RenderFrameHost is created
775 // for the navigation.
776 // PlzNavigate: this will never be set since there are no transferring
777 // navigations in PlzNavigate.
778 scoped_ptr
<NavigationHandleImpl
> transfer_navigation_handle_
;
780 // If either of these is non-NULL, the pending navigation is to a chrome:
781 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is
782 // used for when they reference the same object. If either is non-NULL, the
783 // other should be NULL.
784 // Note: These are not used in PlzNavigate.
785 scoped_ptr
<WebUIImpl
> pending_web_ui_
;
786 base::WeakPtr
<WebUIImpl
> pending_and_current_web_ui_
;
788 class RenderFrameProxyHostMap
;
789 scoped_ptr
<RenderFrameProxyHostMap
> proxy_hosts_
;
791 // A list of RenderFrameHosts waiting to shut down after swapping out. We use
792 // a linked list since we expect frequent deletes and no indexed access, and
793 // because sets don't appear to support linked_ptrs.
794 typedef std::list
<linked_ptr
<RenderFrameHostImpl
> > RFHPendingDeleteList
;
795 RFHPendingDeleteList pending_delete_hosts_
;
797 // The intersitial page currently shown if any, not own by this class
798 // (the InterstitialPage is self-owned, it deletes itself when hidden).
799 InterstitialPageImpl
* interstitial_page_
;
802 // These members store a speculative RenderFrameHost and WebUI. They are
803 // created early in a navigation so a renderer process can be started in
804 // parallel, if needed. This is purely a performance optimization and is not
805 // required for correct behavior. The created RenderFrameHost might be
806 // discarded later on if the final URL's SiteInstance isn't compatible with
807 // what was used to create it.
808 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not
810 scoped_ptr
<RenderFrameHostImpl
> speculative_render_frame_host_
;
811 scoped_ptr
<WebUIImpl
> speculative_web_ui_
;
814 // If true at navigation commit time the current WebUI will be kept instead of
815 // creating a new one.
816 bool should_reuse_web_ui_
;
818 base::WeakPtrFactory
<RenderFrameHostManager
> weak_factory_
;
820 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager
);
823 } // namespace content
825 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_