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"
25 class CrossProcessFrameConnector
;
26 class CrossSiteTransferringRequest
;
28 class InterstitialPageImpl
;
29 class NavigationControllerImpl
;
30 class NavigationEntry
;
31 class NavigationEntryImpl
;
32 class NavigationRequest
;
33 class NavigatorTestWithBrowserSideNavigation
;
34 class RenderFrameHost
;
35 class RenderFrameHostDelegate
;
36 class RenderFrameHostImpl
;
37 class RenderFrameHostManagerTest
;
38 class RenderFrameProxyHost
;
40 class RenderViewHostImpl
;
41 class RenderWidgetHostDelegate
;
42 class RenderWidgetHostView
;
43 class TestWebContents
;
45 struct CommonNavigationParams
;
47 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a
48 // current_frame_host() which is the content currently visible to the user. When
49 // a frame is told to navigate to a different web site (as determined by
50 // SiteInstance), it will replace its current RenderFrameHost with a new
51 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process.
53 // Cross-process navigation works like this:
55 // - RFHM::Navigate determines whether the destination is cross-site, and if so,
56 // it creates a pending_render_frame_host_.
58 // - The pending RFH is created in the "navigations suspended" state, meaning no
59 // navigation messages are sent to its renderer until the beforeunload handler
60 // has a chance to run in the current RFH.
62 // - The current RFH runs its beforeunload handler. If it returns false, we
63 // cancel all the pending logic. Otherwise we allow the pending RFH to send
64 // the navigation request to its renderer.
66 // - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
67 // main resource load from the pending RFH. It creates a
68 // CrossSiteResourceHandler to check whether a process transfer is needed when
69 // the request is ready to commit.
71 // - When RDH receives a response, the BufferedResourceHandler determines
72 // whether it is a navigation type that doesn't commit (e.g. download, 204 or
73 // error page). If so, it sends a message to the new renderer causing it to
74 // cancel the request, and the request (e.g. the download) proceeds. In this
75 // case, the pending RFH will never become the current RFH, but it remains
76 // until the next DidNavigate event for this WebContentsImpl.
78 // - After RDH receives a response and determines that it is safe and not a
79 // download, the CrossSiteResourceHandler checks whether a transfer for a
80 // redirect is needed. If so, it pauses the network response and starts an
81 // identical navigation in a new pending RFH. When the identical request is
82 // later received by RDH, the response is transferred and unpaused.
84 // - Otherwise, the network response commits in the pending RFH's renderer,
85 // which sends a DidCommitProvisionalLoad message back to the browser process.
87 // - RFHM::CommitPending makes visible the new RFH, and initiates the unload
88 // handler in the old RFH. The unload handler will complete in the background.
90 // - RenderFrameHostManager may keep the previous RFH alive as a
91 // RenderFrameProxyHost, to be used (for example) if the user goes back. The
92 // process only stays live if another tab is using it, but if so, the existing
93 // frame relationships will be maintained.
94 class CONTENT_EXPORT RenderFrameHostManager
: public NotificationObserver
{
96 // Functions implemented by our owner that we need.
98 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl
99 // that are required to run this class. The design should probably be better
100 // such that these are more clear.
102 // There is additional complexity that some of the functions we need in
103 // WebContentsImpl are inherited and non-virtual. These are named with
104 // "RenderManager" so that the duplicate implementation of them will be clear.
106 // Functions and parameters whose description are prefixed by PlzNavigate are
107 // part of a navigation refactoring project, currently behind the
108 // enable-browser-side-navigation flag. The idea is to move the logic behind
109 // driving navigations from the renderer to the browser.
110 class CONTENT_EXPORT Delegate
{
112 // Initializes the given renderer if necessary and creates the view ID
113 // corresponding to this view host. If this method is not called and the
114 // process is not shared, then the WebContentsImpl will act as though the
115 // renderer is not running (i.e., it will render "sad tab"). This method is
116 // automatically called from LoadURL. |for_main_frame_navigation| indicates
117 // whether this RenderViewHost is used to render a top-level frame, so the
118 // appropriate RenderWidgetHostView type is used.
119 virtual bool CreateRenderViewForRenderManager(
120 RenderViewHost
* render_view_host
,
122 int proxy_routing_id
,
123 bool for_main_frame_navigation
) = 0;
124 virtual bool CreateRenderFrameForRenderManager(
125 RenderFrameHost
* render_frame_host
,
126 int parent_routing_id
,
127 int proxy_routing_id
) = 0;
128 virtual void BeforeUnloadFiredFromRenderManager(
129 bool proceed
, const base::TimeTicks
& proceed_time
,
130 bool* proceed_to_fire_unload
) = 0;
131 virtual void RenderProcessGoneFromRenderManager(
132 RenderViewHost
* render_view_host
) = 0;
133 virtual void UpdateRenderViewSizeForRenderManager() = 0;
134 virtual void CancelModalDialogsForRenderManager() = 0;
135 virtual void NotifySwappedFromRenderManager(RenderFrameHost
* old_host
,
136 RenderFrameHost
* new_host
,
137 bool is_main_frame
) = 0;
138 // TODO(nasko): This should be removed once extensions no longer use
139 // NotificationService. See https://crbug.com/462682.
140 virtual void NotifyMainFrameSwappedFromRenderManager(
141 RenderViewHost
* old_host
,
142 RenderViewHost
* new_host
) = 0;
143 virtual NavigationControllerImpl
&
144 GetControllerForRenderManager() = 0;
146 // Create swapped out RenderViews in the given SiteInstance for each tab in
147 // the opener chain of this tab, if any. This allows the current tab to
148 // make cross-process script calls to its opener(s). Returns the route ID
149 // of the immediate opener, if one exists (otherwise MSG_ROUTING_NONE).
150 virtual int CreateOpenerRenderViewsForRenderManager(
151 SiteInstance
* instance
) = 0;
153 // Creates a WebUI object for the given URL if one applies. Ownership of the
154 // returned pointer will be passed to the caller. If no WebUI applies,
156 virtual scoped_ptr
<WebUIImpl
> CreateWebUIForRenderManager(
157 const GURL
& url
) = 0;
159 // Returns the navigation entry of the current navigation, or NULL if there
161 virtual NavigationEntry
*
162 GetLastCommittedNavigationEntryForRenderManager() = 0;
164 // Returns true if the location bar should be focused by default rather than
165 // the page contents. The view calls this function when the tab is focused
166 // to see what it should do.
167 virtual bool FocusLocationBarByDefault() = 0;
169 // Focuses the location bar.
170 virtual void SetFocusToLocationBar(bool select_all
) = 0;
172 // Returns true if views created for this delegate should be created in a
174 virtual bool IsHidden() = 0;
177 virtual ~Delegate() {}
180 // Used with FrameTree::ForEach to delete RenderFrameHosts pending shutdown
181 // from a FrameTreeNode's RenderFrameHostManager. Used during destruction of
183 static bool ClearRFHsPendingShutdown(FrameTreeNode
* node
);
185 // All three delegate pointers must be non-NULL and are not owned by this
186 // class. They must outlive this class. The RenderViewHostDelegate and
187 // RenderWidgetHostDelegate are what will be installed into all
188 // RenderViewHosts that are created.
190 // You must call Init() before using this class.
191 RenderFrameHostManager(
192 FrameTreeNode
* frame_tree_node
,
193 RenderFrameHostDelegate
* render_frame_delegate
,
194 RenderViewHostDelegate
* render_view_delegate
,
195 RenderWidgetHostDelegate
* render_widget_delegate
,
197 ~RenderFrameHostManager() override
;
199 // For arguments, see WebContentsImpl constructor.
200 void Init(BrowserContext
* browser_context
,
201 SiteInstance
* site_instance
,
203 int frame_routing_id
);
205 // Returns the currently active RenderFrameHost.
207 // This will be non-NULL between Init() and Shutdown(). You may want to NULL
208 // check it in many cases, however. Windows can send us messages during the
209 // destruction process after it has been shut down.
210 RenderFrameHostImpl
* current_frame_host() const {
211 return render_frame_host_
.get();
214 // TODO(creis): Remove this when we no longer use RVH for navigation.
215 RenderViewHostImpl
* current_host() const;
217 // Returns the view associated with the current RenderViewHost, or NULL if
218 // there is no current one.
219 RenderWidgetHostView
* GetRenderWidgetHostView() const;
221 RenderFrameProxyHost
* GetProxyToParent();
223 // Returns the pending RenderFrameHost, or NULL if there is no pending one.
224 RenderFrameHostImpl
* pending_frame_host() const {
225 return pending_render_frame_host_
.get();
228 // TODO(creis): Remove this when we no longer use RVH for navigation.
229 RenderViewHostImpl
* pending_render_view_host() const;
231 // Returns the current committed Web UI or NULL if none applies.
232 WebUIImpl
* web_ui() const { return web_ui_
.get(); }
234 // Returns the Web UI for the pending navigation, or NULL of none applies.
235 WebUIImpl
* pending_web_ui() const {
236 return pending_web_ui_
.get() ? pending_web_ui_
.get() :
237 pending_and_current_web_ui_
.get();
241 // Returns the speculative WebUI for the navigation (a newly created one or
242 // the current one if it should be reused). If none is set returns nullptr.
243 WebUIImpl
* speculative_web_ui() const {
244 return should_reuse_web_ui_
? web_ui_
.get() : speculative_web_ui_
.get();
247 // Called when we want to instruct the renderer to navigate to the given
248 // navigation entry. It may create a new RenderFrameHost or re-use an existing
249 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one
250 // could not be created.
251 RenderFrameHostImpl
* Navigate(const NavigationEntryImpl
& entry
);
253 // Instructs the various live views to stop. Called when the user directed the
254 // page to stop loading.
257 // Notifies the regular and pending RenderViewHosts that a load is or is not
258 // happening. Even though the message is only for one of them, we don't know
259 // which one so we tell both.
260 void SetIsLoading(bool is_loading
);
262 // Whether to close the tab or not when there is a hang during an unload
263 // handler. If we are mid-crosssite navigation, then we should proceed
264 // with the navigation instead of closing the tab.
265 bool ShouldCloseTabOnUnresponsiveRenderer();
267 // Confirms whether we should close the page or navigate away. This is called
268 // before a cross-site request or before a tab/window is closed (as indicated
269 // by the first parameter) to allow the appropriate renderer to approve or
270 // deny the request. |proceed| indicates whether the user chose to proceed.
271 // |proceed_time| is the time when the request was allowed to proceed.
272 void OnBeforeUnloadACK(bool for_cross_site_transition
,
274 const base::TimeTicks
& proceed_time
);
276 // The |pending_render_frame_host| is ready to commit a page. We should
277 // ensure that the old RenderFrameHost runs its unload handler first and
278 // determine whether a RenderFrameHost transfer is needed.
279 // |cross_site_transferring_request| is NULL if a request is not being
280 // transferred between renderers.
281 void OnCrossSiteResponse(
282 RenderFrameHostImpl
* pending_render_frame_host
,
283 const GlobalRequestID
& global_request_id
,
284 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request
,
285 const std::vector
<GURL
>& transfer_url_chain
,
286 const Referrer
& referrer
,
287 ui::PageTransition page_transition
,
288 bool should_replace_current_entry
);
290 // Received a response from CrossSiteResourceHandler. If the navigation
291 // specifies a transition, this is called and the navigation will not resume
292 // until ResumeResponseDeferredAtStart.
293 void OnDeferredAfterResponseStarted(
294 const GlobalRequestID
& global_request_id
,
295 RenderFrameHostImpl
* pending_render_frame_host
);
297 // Resume navigation paused after receiving response headers.
298 void ResumeResponseDeferredAtStart();
300 // Clear navigation transition data.
301 void ClearNavigationTransitionData();
303 // Called when a renderer's frame navigates.
304 void DidNavigateFrame(RenderFrameHostImpl
* render_frame_host
,
305 bool was_caused_by_user_gesture
);
307 // Called when a renderer sets its opener to null.
308 void DidDisownOpener(RenderFrameHost
* render_frame_host
);
310 // Sets the pending Web UI for the pending navigation, ensuring that the
311 // bindings are appropriate compared to |bindings|.
312 void SetPendingWebUI(const GURL
& url
, int bindings
);
314 // Creates and initializes a RenderFrameHost. The |web_ui| is an optional
315 // input parameter used to double check bindings when swapping back in a
316 // previously existing RenderFrameHost. If |flags| has the
317 // CREATE_RF_SWAPPED_OUT bit set from the CreateRenderFrameFlags enum, it will
318 // initially be placed on the swapped out hosts list. If |view_routing_id_ptr|
319 // is not nullptr it will be set to the routing id of the view associated with
321 scoped_ptr
<RenderFrameHostImpl
> CreateRenderFrame(SiteInstance
* instance
,
325 int* view_routing_id_ptr
);
327 // Helper method to create and initialize a RenderFrameProxyHost and return
329 int CreateRenderFrameProxy(SiteInstance
* instance
);
331 // Creates proxies for a new child frame at FrameTreeNode |child| in all
332 // SiteInstances for which the current frame has proxies. This method is
333 // called on the parent of a new child frame before the child leaves the
335 void CreateProxiesForChildFrame(FrameTreeNode
* child
);
337 // Sets the passed passed interstitial as the currently showing interstitial.
338 // |interstitial_page| should be non NULL (use the remove_interstitial_page
339 // method to unset the interstitial) and no interstitial page should be set
340 // when there is already a non NULL interstitial page set.
341 void set_interstitial_page(InterstitialPageImpl
* interstitial_page
) {
342 DCHECK(!interstitial_page_
&& interstitial_page
);
343 interstitial_page_
= interstitial_page
;
346 // Unsets the currently showing interstitial.
347 void remove_interstitial_page() {
348 DCHECK(interstitial_page_
);
349 interstitial_page_
= NULL
;
352 // Returns the currently showing interstitial, NULL if no interstitial is
354 InterstitialPageImpl
* interstitial_page() const { return interstitial_page_
; }
356 // NotificationObserver implementation.
357 void Observe(int type
,
358 const NotificationSource
& source
,
359 const NotificationDetails
& details
) override
;
361 // Returns whether the given RenderFrameHost (or its associated
362 // RenderViewHost) is on the list of swapped out RenderFrameHosts.
363 bool IsRVHOnSwappedOutList(RenderViewHostImpl
* rvh
) const;
364 bool IsOnSwappedOutList(RenderFrameHostImpl
* rfh
) const;
366 // Returns the swapped out RenderViewHost or RenderFrameHost for the given
367 // SiteInstance, if any. This method is *deprecated* and
368 // GetRenderFrameProxyHost should be used.
369 RenderViewHostImpl
* GetSwappedOutRenderViewHost(SiteInstance
* instance
) const;
370 RenderFrameProxyHost
* GetRenderFrameProxyHost(
371 SiteInstance
* instance
) const;
373 // Returns whether |render_frame_host| is on the pending deletion list.
374 bool IsPendingDeletion(RenderFrameHostImpl
* render_frame_host
);
376 // If |render_frame_host| is on the pending deletion list, this deletes it.
377 // Returns whether it was deleted.
378 bool DeleteFromPendingList(RenderFrameHostImpl
* render_frame_host
);
380 // Deletes any proxy hosts associated with this node. Used during destruction
381 // of WebContentsImpl.
382 void ResetProxyHosts();
384 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy
385 // that has the given SiteInstance and is associated with this
386 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found.
387 int GetRoutingIdForSiteInstance(SiteInstance
* site_instance
);
390 // Notifies the RFHM that a navigation has begun so that it can speculatively
391 // create a new RenderFrameHost (and potentially a new process) if needed.
392 void BeginNavigation(const NavigationRequest
& request
);
395 // Called (possibly several times) during a navigation to select or create an
396 // appropriate RenderFrameHost for the provided URL. The returned pointer will
397 // be for the current or the speculative RenderFrameHost and the instance is
398 // owned by this manager.
399 RenderFrameHostImpl
* GetFrameHostForNavigation(
400 const NavigationRequest
& request
);
403 // Clean up any state for any ongoing navigation.
404 void CleanUpNavigation();
407 // Clears the speculative members, returning the RenderFrameHost to the caller
409 scoped_ptr
<RenderFrameHostImpl
> UnsetSpeculativeRenderFrameHost();
411 // Notification methods to tell this RenderFrameHostManager that the frame it
412 // is responsible for has started or stopped loading a document.
413 void OnDidStartLoading();
414 void OnDidStopLoading();
416 // Send updated frame name to all frame proxies when the frame changes its
417 // window.name property.
418 void OnDidUpdateName(const std::string
& name
);
420 void EnsureRenderViewInitialized(FrameTreeNode
* source
,
421 RenderViewHostImpl
* render_view_host
,
422 SiteInstance
* instance
);
425 friend class NavigatorTestWithBrowserSideNavigation
;
426 friend class RenderFrameHostManagerTest
;
427 friend class TestWebContents
;
429 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest
,
430 CreateCrossProcessSubframeProxies
);
432 // Stores information regarding a SiteInstance targeted at a specific URL to
433 // allow for comparisons without having to actually create new instances. It
434 // can point to an existing one or store the details needed to create a new
436 struct CONTENT_EXPORT SiteInstanceDescriptor
{
437 explicit SiteInstanceDescriptor(content::SiteInstance
* site_instance
)
438 : existing_site_instance(site_instance
),
439 new_is_related_to_current(false) {}
441 SiteInstanceDescriptor(BrowserContext
* browser_context
,
443 bool related_to_current
);
445 // Set with an existing SiteInstance to be reused.
446 content::SiteInstance
* existing_site_instance
;
448 // In case |existing_site_instance| is null, specify a new site URL.
451 // In case |existing_site_instance| is null, specify if the new site should
452 // be created in a new BrowsingInstance or not.
453 bool new_is_related_to_current
;
456 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a
457 // FrameTreeNode's RenderFrameHostManager.
458 static bool ClearProxiesInSiteInstance(int32 site_instance_id
,
459 FrameTreeNode
* node
);
460 // Used with FrameTree::ForEach to reset initialized state of
461 // RenderFrameProxyHosts from a FrameTreeNode's RenderFrameHostManager.
462 static bool ResetProxiesInSiteInstance(int32 site_instance_id
,
463 FrameTreeNode
* node
);
465 // Returns whether this tab should transition to a new renderer for
466 // cross-site URLs. Enabled unless we see the --process-per-tab command line
467 // switch. Can be overridden in unit tests.
468 bool ShouldTransitionCrossSite();
470 // Returns true if for the navigation from |current_effective_url| to
471 // |new_effective_url|, a new SiteInstance and BrowsingInstance should be
472 // created (even if we are in a process model that doesn't usually swap).
473 // This forces a process swap and severs script connections with existing
474 // tabs. Cases where this can happen include transitions between WebUI and
475 // regular web pages. |new_site_instance| may be null.
476 // If there is no current NavigationEntry, then |current_is_view_source_mode|
477 // should be the same as |new_is_view_source_mode|.
479 // We use the effective URL here, since that's what is used in the
480 // SiteInstance's site and when we later call IsSameWebSite. If there is no
481 // current NavigationEntry, check the current SiteInstance's site, which might
482 // already be committed to a Web UI URL (such as the NTP).
483 bool ShouldSwapBrowsingInstancesForNavigation(
484 const GURL
& current_effective_url
,
485 bool current_is_view_source_mode
,
486 SiteInstance
* new_site_instance
,
487 const GURL
& new_effective_url
,
488 bool new_is_view_source_mode
) const;
490 // Creates a new Web UI, ensuring that the bindings are appropriate compared
492 scoped_ptr
<WebUIImpl
> CreateWebUI(const GURL
& url
, int bindings
);
494 // Returns true if it is safe to reuse the current WebUI when navigating from
495 // |current_entry| to |new_url|.
496 bool ShouldReuseWebUI(
497 const NavigationEntry
* current_entry
,
498 const GURL
& new_url
) const;
500 // Returns the SiteInstance to use for the navigation.
501 SiteInstance
* GetSiteInstanceForNavigation(const GURL
& dest_url
,
502 SiteInstance
* source_instance
,
503 SiteInstance
* dest_instance
,
504 SiteInstance
* candidate_instance
,
505 ui::PageTransition transition
,
506 bool dest_is_restore
,
507 bool dest_is_view_source_mode
);
509 // Returns a descriptor of the appropriate SiteInstance object for the given
510 // |dest_url|, possibly reusing the current, source or destination
511 // SiteInstance. The actual SiteInstance can then be obtained calling
512 // ConvertToSiteInstance with the descriptor.
514 // |source_instance| is the SiteInstance of the frame that initiated the
515 // navigation. |current_instance| is the SiteInstance of the frame that is
516 // currently navigating. |dest_instance| is a predetermined SiteInstance that
517 // will be used if not null.
518 // For example, if you have a parent frame A, which has a child frame B, and
519 // A is trying to change the src attribute of B, this will cause a navigation
520 // where the source SiteInstance is A and B is the current SiteInstance.
522 // This is a helper function for GetSiteInstanceForNavigation.
523 SiteInstanceDescriptor
DetermineSiteInstanceForURL(
524 const GURL
& dest_url
,
525 SiteInstance
* source_instance
,
526 SiteInstance
* current_instance
,
527 SiteInstance
* dest_instance
,
528 ui::PageTransition transition
,
529 bool dest_is_restore
,
530 bool dest_is_view_source_mode
,
531 bool force_browsing_instance_swap
);
533 // Converts a SiteInstanceDescriptor to the actual SiteInstance it describes.
534 // If a |candidate_instance| is provided (is not nullptr) and it matches the
535 // description, it is returned as is.
536 SiteInstance
* ConvertToSiteInstance(const SiteInstanceDescriptor
& descriptor
,
537 SiteInstance
* candidate_instance
);
539 // Determines the appropriate url to use as the current url for SiteInstance
541 const GURL
& GetCurrentURLForSiteInstance(
542 SiteInstance
* current_instance
,
543 NavigationEntry
* current_entry
);
545 // Creates a new RenderFrameHostImpl for the |new_instance| and assign it to
546 // |pending_render_frame_host_| while respecting the opener route if needed
547 // and stores it in pending_render_frame_host_.
548 void CreatePendingRenderFrameHost(SiteInstance
* old_instance
,
549 SiteInstance
* new_instance
,
552 // Ensure that we have created RFHs for the new RFH's opener chain if
553 // we are staying in the same BrowsingInstance. This allows the new RFH
554 // to send cross-process script calls to its opener(s). Returns the opener
555 // route ID to be used for the new RenderView to be created.
556 // |create_render_frame_flags| allows the method to set additional flags.
557 int CreateOpenerRenderViewsIfNeeded(SiteInstance
* old_instance
,
558 SiteInstance
* new_instance
,
559 int* create_render_frame_flags
);
561 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
562 scoped_ptr
<RenderFrameHostImpl
> CreateRenderFrameHost(SiteInstance
* instance
,
564 int frame_routing_id
,
568 // Creates and initializes a speculative RenderFrameHost and/or WebUI for an
569 // ongoing navigation. They might be destroyed and re-created later if the
570 // navigation is redirected to a different SiteInstance.
571 bool CreateSpeculativeRenderFrameHost(const GURL
& url
,
572 SiteInstance
* old_instance
,
573 SiteInstance
* new_instance
,
576 // Sets up the necessary state for a new RenderViewHost with the given opener,
577 // if necessary. It creates a RenderFrameProxy in the target renderer process
578 // with the given |proxy_routing_id|, which is used to route IPC messages when
579 // in swapped out state. Returns early if the RenderViewHost has already been
580 // initialized for another RenderFrameHost.
581 // TODO(creis): opener_route_id is currently for the RenderViewHost but should
582 // be for the RenderFrame, since frames can have openers.
583 bool InitRenderView(RenderViewHostImpl
* render_view_host
,
585 int proxy_routing_id
,
586 bool for_main_frame_navigation
);
588 // Initialization for RenderFrameHost uses the same sequence as InitRenderView
590 bool InitRenderFrame(RenderFrameHostImpl
* render_frame_host
);
592 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
593 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
594 // since there could be Web UI switching as well. Call this for every commit.
595 // If PlzNavigate is enabled the method will set the speculative (not pending)
596 // RenderFrameHost to be the active one.
597 void CommitPending();
599 // Helper to call CommitPending() in all necessary cases.
600 void CommitPendingIfNecessary(RenderFrameHostImpl
* render_frame_host
,
601 bool was_caused_by_user_gesture
);
603 // Commits any pending sandbox flag updates when the renderer's frame
605 void CommitPendingSandboxFlags();
607 // Runs the unload handler in the old RenderFrameHost, after the new
608 // RenderFrameHost has committed. |old_render_frame_host| will either be
609 // deleted or put on the pending delete list during this call.
610 void SwapOutOldFrame(scoped_ptr
<RenderFrameHostImpl
> old_render_frame_host
);
612 // Discards a RenderFrameHost that was never made active (for active ones
613 // SwapOutOldFrame is used instead).
614 void DiscardUnusedFrame(scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
616 // Holds |render_frame_host| until it can be deleted when its swap out ACK
618 void MoveToPendingDeleteHosts(
619 scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
621 // If |render_frame_host| is the last remaining active frame in its
622 // SiteInstance, this will shutdown all the RenderFrameProxyHosts in the
623 // SiteInstance. This is appropriate if |render_frame_host| is about to be
625 void ShutdownProxiesIfLastActiveFrameInSiteInstance(
626 RenderFrameHostImpl
* render_frame_host
);
628 // Helper method to terminate the pending RenderFrameHost. The frame may be
629 // deleted immediately, or it may be kept around in hopes of later reuse.
630 void CancelPending();
632 // Clears pending_render_frame_host_, returning it to the caller for disposal.
633 scoped_ptr
<RenderFrameHostImpl
> UnsetPendingRenderFrameHost();
635 // Helper method to set the active RenderFrameHost. Returns the old
636 // RenderFrameHost and updates counts.
637 scoped_ptr
<RenderFrameHostImpl
> SetRenderFrameHost(
638 scoped_ptr
<RenderFrameHostImpl
> render_frame_host
);
640 RenderFrameHostImpl
* UpdateStateForNavigate(
641 const GURL
& dest_url
,
642 SiteInstance
* source_instance
,
643 SiteInstance
* dest_instance
,
644 ui::PageTransition transition
,
645 bool dest_is_restore
,
646 bool dest_is_view_source_mode
,
647 const GlobalRequestID
& transferred_request_id
,
650 // Called when a renderer process is starting to close. We should not
651 // schedule new navigations in its swapped out RenderFrameHosts after this.
652 void RendererProcessClosing(RenderProcessHost
* render_process_host
);
654 // Helper method to delete a RenderFrameProxyHost from the list, if one exists
655 // for the given |instance|.
656 void DeleteRenderFrameProxyHost(SiteInstance
* instance
);
658 // For use in creating RenderFrameHosts.
659 FrameTreeNode
* frame_tree_node_
;
661 // Our delegate, not owned by us. Guaranteed non-NULL.
664 // Whether a navigation requiring different RenderFrameHosts is pending. This
665 // is either for cross-site requests or when required for the process type
667 // PlzNavigate: |cross_navigation_pending_| is not used for browser-side
669 bool cross_navigation_pending_
;
671 // Implemented by the owner of this class. These delegates are installed into
672 // all the RenderFrameHosts that we create.
673 RenderFrameHostDelegate
* render_frame_delegate_
;
674 RenderViewHostDelegate
* render_view_delegate_
;
675 RenderWidgetHostDelegate
* render_widget_delegate_
;
677 // Our RenderFrameHost and its associated Web UI (if any, will be NULL for
678 // non-WebUI pages). This object is responsible for all communication with
679 // a child RenderFrame instance.
680 // For now, RenderFrameHost keeps a RenderViewHost in its SiteInstance alive.
681 // Eventually, RenderViewHost will be replaced with a page context.
682 scoped_ptr
<RenderFrameHostImpl
> render_frame_host_
;
683 scoped_ptr
<WebUIImpl
> web_ui_
;
685 // A RenderFrameHost used to load a cross-site page. This remains hidden
686 // while a cross-site request is pending until it calls DidNavigate. It may
687 // have an associated Web UI, in which case the Web UI pointer will be non-
690 // The |pending_web_ui_| may be non-NULL even when the
691 // |pending_render_frame_host_| is NULL. This will happen when we're
692 // transitioning between two Web UI pages: the RFH won't be swapped, so the
693 // pending pointer will be unused, but there will be a pending Web UI
694 // associated with the navigation.
695 // Note: This is not used in PlzNavigate.
696 scoped_ptr
<RenderFrameHostImpl
> pending_render_frame_host_
;
698 // If a pending request needs to be transferred to another process, this
699 // owns the request until it's transferred to the new process, so it will be
700 // cleaned up if the navigation is cancelled. Otherwise, this is NULL.
701 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request_
;
703 // Tracks information about any navigation paused after receiving response
705 scoped_ptr
<GlobalRequestID
> response_started_id_
;
707 // If either of these is non-NULL, the pending navigation is to a chrome:
708 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is
709 // used for when they reference the same object. If either is non-NULL, the
710 // other should be NULL.
711 // Note: These are not used in PlzNavigate.
712 scoped_ptr
<WebUIImpl
> pending_web_ui_
;
713 base::WeakPtr
<WebUIImpl
> pending_and_current_web_ui_
;
715 // A map of site instance ID to RenderFrameProxyHosts.
716 typedef base::hash_map
<int32
, RenderFrameProxyHost
*> RenderFrameProxyHostMap
;
717 RenderFrameProxyHostMap proxy_hosts_
;
719 // A list of RenderFrameHosts waiting to shut down after swapping out. We use
720 // a linked list since we expect frequent deletes and no indexed access, and
721 // because sets don't appear to support linked_ptrs.
722 typedef std::list
<linked_ptr
<RenderFrameHostImpl
> > RFHPendingDeleteList
;
723 RFHPendingDeleteList pending_delete_hosts_
;
725 // The intersitial page currently shown if any, not own by this class
726 // (the InterstitialPage is self-owned, it deletes itself when hidden).
727 InterstitialPageImpl
* interstitial_page_
;
729 NotificationRegistrar registrar_
;
732 // These members store a speculative RenderFrameHost and WebUI. They are
733 // created early in a navigation so a renderer process can be started in
734 // parallel, if needed. This is purely a performance optimization and is not
735 // required for correct behavior. The created RenderFrameHost might be
736 // discarded later on if the final URL's SiteInstance isn't compatible with
737 // what was used to create it.
738 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not
740 scoped_ptr
<RenderFrameHostImpl
> speculative_render_frame_host_
;
741 scoped_ptr
<WebUIImpl
> speculative_web_ui_
;
744 // If true at navigation commit time the current WebUI will be kept instead of
745 // creating a new one.
746 bool should_reuse_web_ui_
;
748 base::WeakPtrFactory
<RenderFrameHostManager
> weak_factory_
;
750 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager
);
753 } // namespace content
755 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_