Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / content / browser / frame_host / render_frame_host_manager.h
blob1359e9f74e425e836ef6c4ffbeb6bd21662c3e3b
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_
8 #include <list>
9 #include <map>
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"
23 namespace content {
24 class BrowserContext;
25 class CrossProcessFrameConnector;
26 class CrossSiteTransferringRequest;
27 class FrameNavigationEntry;
28 class FrameTreeNode;
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;
41 class RenderViewHost;
42 class RenderViewHostImpl;
43 class RenderWidgetHostDelegate;
44 class RenderWidgetHostView;
45 class TestWebContents;
46 class WebUIImpl;
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 {
98 public:
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 {
114 public:
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,
124 int opener_frame_routing_id,
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,
153 // returns NULL.
154 virtual scoped_ptr<WebUIImpl> CreateWebUIForRenderManager(
155 const GURL& url) = 0;
157 // Returns the navigation entry of the current navigation, or NULL if there
158 // is none.
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
171 // hidden state.
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;
180 protected:
181 virtual ~Delegate() {}
184 // Used with FrameTree::ForEach to delete RenderFrameHosts pending shutdown
185 // from a FrameTreeNode's RenderFrameHostManager. Used during destruction of
186 // WebContentsImpl.
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,
200 Delegate* delegate);
201 ~RenderFrameHostManager();
203 // For arguments, see WebContentsImpl constructor.
204 void Init(BrowserContext* browser_context,
205 SiteInstance* site_instance,
206 int view_routing_id,
207 int frame_routing_id);
209 // Returns the currently active RenderFrameHost.
211 // This will be non-NULL between Init() and Shutdown(). You may want to NULL
212 // check it in many cases, however. Windows can send us messages during the
213 // destruction process after it has been shut down.
214 RenderFrameHostImpl* current_frame_host() const {
215 return render_frame_host_.get();
218 // TODO(creis): Remove this when we no longer use RVH for navigation.
219 RenderViewHostImpl* current_host() const;
221 // Returns the view associated with the current RenderViewHost, or NULL if
222 // there is no current one.
223 RenderWidgetHostView* GetRenderWidgetHostView() const;
225 // Returns whether this manager belongs to a FrameTreeNode that is a main
226 // frame in an inner WebContents.
227 // TODO(lazyboy): Make this work correctly for subframes inside inner
228 // WebContents too.
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
234 // remote frames.
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
241 // relationship.
242 RenderFrameProxyHost* GetProxyToOuterDelegate();
244 // Removes the FrameTreeNode in the outer WebContents that represents this
245 // FrameTreeNode.
246 // TODO(lazyboy): This does not belong to RenderFrameHostManager, move it to
247 // somehwere else.
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
256 // one.
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();
273 // PlzNavigate
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.
292 void Stop();
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,
310 bool proceed,
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 a renderer sets its opener to null.
332 void DidDisownOpener(RenderFrameHost* render_frame_host);
334 // Sets the pending Web UI for the pending navigation, ensuring that the
335 // bindings are appropriate compared to |bindings|.
336 void SetPendingWebUI(const GURL& url, int bindings);
338 // Creates and initializes a RenderFrameHost. The |web_ui| is an optional
339 // input parameter used to double check bindings when swapping back in a
340 // previously existing RenderFrameHost. If |flags| has the
341 // CREATE_RF_SWAPPED_OUT bit set from the CreateRenderFrameFlags enum, it will
342 // initially be placed on the swapped out hosts list. If |view_routing_id_ptr|
343 // is not nullptr it will be set to the routing id of the view associated with
344 // the frame.
345 scoped_ptr<RenderFrameHostImpl> CreateRenderFrame(SiteInstance* instance,
346 WebUIImpl* web_ui,
347 int flags,
348 int* view_routing_id_ptr);
350 // Helper method to create and initialize a RenderFrameProxyHost and return
351 // its routing id.
352 int CreateRenderFrameProxy(SiteInstance* instance);
354 // Creates proxies for a new child frame at FrameTreeNode |child| in all
355 // SiteInstances for which the current frame has proxies. This method is
356 // called on the parent of a new child frame before the child leaves the
357 // SiteInstance.
358 void CreateProxiesForChildFrame(FrameTreeNode* child);
360 // Sets the passed passed interstitial as the currently showing interstitial.
361 // |interstitial_page| should be non NULL (use the remove_interstitial_page
362 // method to unset the interstitial) and no interstitial page should be set
363 // when there is already a non NULL interstitial page set.
364 void set_interstitial_page(InterstitialPageImpl* interstitial_page) {
365 DCHECK(!interstitial_page_ && interstitial_page);
366 interstitial_page_ = interstitial_page;
369 // Unsets the currently showing interstitial.
370 void remove_interstitial_page() {
371 DCHECK(interstitial_page_);
372 interstitial_page_ = NULL;
375 // Returns the currently showing interstitial, NULL if no interstitial is
376 // showing.
377 InterstitialPageImpl* interstitial_page() const { return interstitial_page_; }
379 // Returns whether the given RenderFrameHost (or its associated
380 // RenderViewHost) is on the list of swapped out RenderFrameHosts.
381 bool IsRVHOnSwappedOutList(RenderViewHostImpl* rvh) const;
382 bool IsOnSwappedOutList(RenderFrameHostImpl* rfh) const;
384 // Returns the swapped out RenderViewHost for the given SiteInstance, if any.
385 // This method is *deprecated* and GetRenderFrameProxyHost should be used.
386 RenderViewHostImpl* GetSwappedOutRenderViewHost(SiteInstance* instance) const;
388 // Returns the RenderFrameProxyHost for the given SiteInstance, if any.
389 RenderFrameProxyHost* GetRenderFrameProxyHost(
390 SiteInstance* instance) const;
392 // Returns whether |render_frame_host| is on the pending deletion list.
393 bool IsPendingDeletion(RenderFrameHostImpl* render_frame_host);
395 // If |render_frame_host| is on the pending deletion list, this deletes it.
396 // Returns whether it was deleted.
397 bool DeleteFromPendingList(RenderFrameHostImpl* render_frame_host);
399 // Deletes any proxy hosts associated with this node. Used during destruction
400 // of WebContentsImpl.
401 void ResetProxyHosts();
403 // Returns the routing id for a RenderFrameHost or RenderFrameProxyHost
404 // that has the given SiteInstance and is associated with this
405 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found.
406 int GetRoutingIdForSiteInstance(SiteInstance* site_instance);
408 // PlzNavigate
409 // Notifies the RenderFrameHostManager that a new NavigationRequest has been
410 // created and set in the FrameTreeNode so that it can speculatively create a
411 // new RenderFrameHost (and potentially a new process) if needed.
412 void DidCreateNavigationRequest(const NavigationRequest& request);
414 // PlzNavigate
415 // Called (possibly several times) during a navigation to select or create an
416 // appropriate RenderFrameHost for the provided URL. The returned pointer will
417 // be for the current or the speculative RenderFrameHost and the instance is
418 // owned by this manager.
419 RenderFrameHostImpl* GetFrameHostForNavigation(
420 const NavigationRequest& request);
422 // PlzNavigate
423 // Clean up any state for any ongoing navigation.
424 void CleanUpNavigation();
426 // PlzNavigate
427 // Clears the speculative members, returning the RenderFrameHost to the caller
428 // for disposal.
429 scoped_ptr<RenderFrameHostImpl> UnsetSpeculativeRenderFrameHost();
431 // Notification methods to tell this RenderFrameHostManager that the frame it
432 // is responsible for has started or stopped loading a document.
433 void OnDidStartLoading();
434 void OnDidStopLoading();
436 // Send updated frame name to all frame proxies when the frame changes its
437 // window.name property.
438 void OnDidUpdateName(const std::string& name);
440 // Send updated origin to all frame proxies when the frame navigates to a new
441 // origin.
442 void OnDidUpdateOrigin(const url::Origin& origin);
444 void EnsureRenderViewInitialized(RenderViewHostImpl* render_view_host,
445 SiteInstance* instance);
447 // Recursively creates swapped out RenderViews and RenderFrameProxies for
448 // this frame's FrameTree and for its opener chain in the given SiteInstance.
449 // This allows other tabs to send cross-process JavaScript calls to their
450 // opener(s) and to any other frames in the opener's FrameTree (e.g.,
451 // supporting calls like window.opener.opener.frames[x][y]).
452 void CreateOpenerProxies(SiteInstance* instance);
454 // Ensure that this frame has proxies in all SiteInstances that can discover
455 // this frame by name (e.g., via window.open("", "frame_name")). See
456 // https://crbug.com/511474.
457 void CreateProxiesForNewNamedFrame();
459 // Returns a routing ID for the current FrameTreeNode's opener node in the
460 // given SiteInstance. May return a routing ID of either a RenderFrameHost
461 // (if opener's current or pending RFH has SiteInstance |instance|) or a
462 // RenderFrameProxyHost. Returns MSG_ROUTING_NONE if there is no opener, or
463 // if the opener node doesn't have a proxy for |instance|.
464 int GetOpenerRoutingID(SiteInstance* instance);
466 // Called on the RFHM of the inner WebContents to create a
467 // RenderFrameProxyHost in its outer WebContents's SiteInstance,
468 // |outer_contents_site_instance|. The frame in outer WebContents that is
469 // hosting the inner WebContents is |render_frame_host|, and the frame will
470 // be swapped out with the proxy.
471 void CreateOuterDelegateProxy(SiteInstance* outer_contents_site_instance,
472 RenderFrameHostImpl* render_frame_host);
474 // Sets the child RenderWidgetHostView for this frame, which must be part of
475 // an inner WebContents.
476 void SetRWHViewForInnerContents(RenderWidgetHostView* child_rwhv);
478 // Returns a copy of the map of proxy hosts. The keys are SiteInstance IDs,
479 // the values are RenderFrameProxyHosts.
480 std::map<int, RenderFrameProxyHost*> GetAllProxyHostsForTesting();
482 private:
483 friend class NavigatorTestWithBrowserSideNavigation;
484 friend class RenderFrameHostManagerTest;
485 friend class TestWebContents;
487 // Stores information regarding a SiteInstance targeted at a specific URL to
488 // allow for comparisons without having to actually create new instances. It
489 // can point to an existing one or store the details needed to create a new
490 // one.
491 struct CONTENT_EXPORT SiteInstanceDescriptor {
492 explicit SiteInstanceDescriptor(content::SiteInstance* site_instance)
493 : existing_site_instance(site_instance),
494 new_is_related_to_current(false) {}
496 SiteInstanceDescriptor(BrowserContext* browser_context,
497 GURL dest_url,
498 bool related_to_current);
500 // Set with an existing SiteInstance to be reused.
501 content::SiteInstance* existing_site_instance;
503 // In case |existing_site_instance| is null, specify a new site URL.
504 GURL new_site_url;
506 // In case |existing_site_instance| is null, specify if the new site should
507 // be created in a new BrowsingInstance or not.
508 bool new_is_related_to_current;
511 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a
512 // FrameTreeNode's RenderFrameHostManager.
513 static bool ClearProxiesInSiteInstance(int32 site_instance_id,
514 FrameTreeNode* node);
515 // Used with FrameTree::ForEach to reset initialized state of
516 // RenderFrameProxyHosts from a FrameTreeNode's RenderFrameHostManager.
517 static bool ResetProxiesInSiteInstance(int32 site_instance_id,
518 FrameTreeNode* node);
520 // Returns whether this tab should transition to a new renderer for
521 // cross-site URLs. Enabled unless we see the --process-per-tab command line
522 // switch. Can be overridden in unit tests.
523 bool ShouldTransitionCrossSite();
525 // Returns true if for the navigation from |current_effective_url| to
526 // |new_effective_url|, a new SiteInstance and BrowsingInstance should be
527 // created (even if we are in a process model that doesn't usually swap).
528 // This forces a process swap and severs script connections with existing
529 // tabs. Cases where this can happen include transitions between WebUI and
530 // regular web pages. |new_site_instance| may be null.
531 // If there is no current NavigationEntry, then |current_is_view_source_mode|
532 // should be the same as |new_is_view_source_mode|.
534 // We use the effective URL here, since that's what is used in the
535 // SiteInstance's site and when we later call IsSameWebSite. If there is no
536 // current NavigationEntry, check the current SiteInstance's site, which might
537 // already be committed to a Web UI URL (such as the NTP).
538 bool ShouldSwapBrowsingInstancesForNavigation(
539 const GURL& current_effective_url,
540 bool current_is_view_source_mode,
541 SiteInstance* new_site_instance,
542 const GURL& new_effective_url,
543 bool new_is_view_source_mode) const;
545 // Creates a new Web UI, ensuring that the bindings are appropriate compared
546 // to |bindings|.
547 scoped_ptr<WebUIImpl> CreateWebUI(const GURL& url, int bindings);
549 // Returns true if it is safe to reuse the current WebUI when navigating from
550 // |current_entry| to |new_url|.
551 bool ShouldReuseWebUI(
552 const NavigationEntry* current_entry,
553 const GURL& new_url) const;
555 // Returns the SiteInstance to use for the navigation.
556 SiteInstance* GetSiteInstanceForNavigation(const GURL& dest_url,
557 SiteInstance* source_instance,
558 SiteInstance* dest_instance,
559 SiteInstance* candidate_instance,
560 ui::PageTransition transition,
561 bool dest_is_restore,
562 bool dest_is_view_source_mode);
564 // Returns a descriptor of the appropriate SiteInstance object for the given
565 // |dest_url|, possibly reusing the current, source or destination
566 // SiteInstance. The actual SiteInstance can then be obtained calling
567 // ConvertToSiteInstance with the descriptor.
569 // |source_instance| is the SiteInstance of the frame that initiated the
570 // navigation. |current_instance| is the SiteInstance of the frame that is
571 // currently navigating. |dest_instance| is a predetermined SiteInstance that
572 // will be used if not null.
573 // For example, if you have a parent frame A, which has a child frame B, and
574 // A is trying to change the src attribute of B, this will cause a navigation
575 // where the source SiteInstance is A and B is the current SiteInstance.
577 // This is a helper function for GetSiteInstanceForNavigation.
578 SiteInstanceDescriptor DetermineSiteInstanceForURL(
579 const GURL& dest_url,
580 SiteInstance* source_instance,
581 SiteInstance* current_instance,
582 SiteInstance* dest_instance,
583 ui::PageTransition transition,
584 bool dest_is_restore,
585 bool dest_is_view_source_mode,
586 bool force_browsing_instance_swap);
588 // Converts a SiteInstanceDescriptor to the actual SiteInstance it describes.
589 // If a |candidate_instance| is provided (is not nullptr) and it matches the
590 // description, it is returned as is.
591 SiteInstance* ConvertToSiteInstance(const SiteInstanceDescriptor& descriptor,
592 SiteInstance* candidate_instance);
594 // Determines the appropriate url to use as the current url for SiteInstance
595 // selection.
596 const GURL& GetCurrentURLForSiteInstance(
597 SiteInstance* current_instance,
598 NavigationEntry* current_entry);
600 // Creates a new RenderFrameHostImpl for the |new_instance| and assign it to
601 // |pending_render_frame_host_| while respecting the opener route if needed
602 // and stores it in pending_render_frame_host_.
603 void CreatePendingRenderFrameHost(SiteInstance* old_instance,
604 SiteInstance* new_instance,
605 bool is_main_frame);
607 // Ensure that we have created all needed proxies for a new RFH with
608 // SiteInstance |new_instance|: (1) create swapped-out RVHs and proxies for
609 // the new RFH's opener chain if we are staying in the same BrowsingInstance;
610 // (2) Create proxies for the new RFH's SiteInstance in its own frame tree;
611 // (3) set any additional flags for the new RenderFrame with
612 // |create_render_frame_flags|.
613 void CreateProxiesForNewRenderFrameHost(SiteInstance* old_instance,
614 SiteInstance* new_instance,
615 int* create_render_frame_flags);
617 // Create swapped out RenderViews and RenderFrameProxies in the given
618 // SiteInstance for all frames on the opener chain of this frame. Same as
619 // CreateOpenerProxies, but starts from this frame's opener, calling
620 // CreateOpenerProxies on it if it exists and returning otherwise.
621 void CreateOpenerProxiesIfNeeded(SiteInstance* instance);
623 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
624 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance,
625 int view_routing_id,
626 int frame_routing_id,
627 int flags);
629 // PlzNavigate
630 // Creates and initializes a speculative RenderFrameHost and/or WebUI for an
631 // ongoing navigation. They might be destroyed and re-created later if the
632 // navigation is redirected to a different SiteInstance.
633 bool CreateSpeculativeRenderFrameHost(const GURL& url,
634 SiteInstance* old_instance,
635 SiteInstance* new_instance,
636 int bindings);
638 // Sets up the necessary state for a new RenderViewHost. Creates a
639 // RenderFrameProxy in the target renderer process with the given
640 // |proxy_routing_id|, which is used to route IPC messages when in swapped
641 // out state. Returns early if the RenderViewHost has already been
642 // initialized for another RenderFrameHost.
643 bool InitRenderView(RenderViewHostImpl* render_view_host,
644 int proxy_routing_id,
645 bool for_main_frame_navigation);
647 // Initialization for RenderFrameHost uses the same sequence as InitRenderView
648 // above.
649 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host);
651 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
652 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
653 // since there could be Web UI switching as well. Call this for every commit.
654 // If PlzNavigate is enabled the method will set the speculative (not pending)
655 // RenderFrameHost to be the active one.
656 void CommitPending();
658 // Helper to call CommitPending() in all necessary cases.
659 void CommitPendingIfNecessary(RenderFrameHostImpl* render_frame_host,
660 bool was_caused_by_user_gesture);
662 // Commits any pending sandbox flag updates when the renderer's frame
663 // navigates.
664 void CommitPendingSandboxFlags();
666 // Runs the unload handler in the old RenderFrameHost, after the new
667 // RenderFrameHost has committed. |old_render_frame_host| will either be
668 // deleted or put on the pending delete list during this call.
669 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host);
671 // Discards a RenderFrameHost that was never made active (for active ones
672 // SwapOutOldFrame is used instead).
673 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host);
675 // Holds |render_frame_host| until it can be deleted when its swap out ACK
676 // arrives.
677 void MoveToPendingDeleteHosts(
678 scoped_ptr<RenderFrameHostImpl> render_frame_host);
680 // If |render_frame_host| is the last remaining active frame in its
681 // SiteInstance, this will shutdown all the RenderFrameProxyHosts in the
682 // SiteInstance. This is appropriate if |render_frame_host| is about to be
683 // destroyed.
684 void ShutdownProxiesIfLastActiveFrameInSiteInstance(
685 RenderFrameHostImpl* render_frame_host);
687 // Helper method to terminate the pending RenderFrameHost. The frame may be
688 // deleted immediately, or it may be kept around in hopes of later reuse.
689 void CancelPending();
691 // Clears pending_render_frame_host_, returning it to the caller for disposal.
692 scoped_ptr<RenderFrameHostImpl> UnsetPendingRenderFrameHost();
694 // Helper method to set the active RenderFrameHost. Returns the old
695 // RenderFrameHost and updates counts.
696 scoped_ptr<RenderFrameHostImpl> SetRenderFrameHost(
697 scoped_ptr<RenderFrameHostImpl> render_frame_host);
699 RenderFrameHostImpl* UpdateStateForNavigate(
700 const GURL& dest_url,
701 SiteInstance* source_instance,
702 SiteInstance* dest_instance,
703 ui::PageTransition transition,
704 bool dest_is_restore,
705 bool dest_is_view_source_mode,
706 const GlobalRequestID& transferred_request_id,
707 int bindings);
709 // Called when a renderer process is starting to close. We should not
710 // schedule new navigations in its swapped out RenderFrameHosts after this.
711 void RendererProcessClosing(RenderProcessHost* render_process_host);
713 // For use in creating RenderFrameHosts.
714 FrameTreeNode* frame_tree_node_;
716 // Our delegate, not owned by us. Guaranteed non-NULL.
717 Delegate* delegate_;
719 // Implemented by the owner of this class. These delegates are installed into
720 // all the RenderFrameHosts that we create.
721 RenderFrameHostDelegate* render_frame_delegate_;
722 RenderViewHostDelegate* render_view_delegate_;
723 RenderWidgetHostDelegate* render_widget_delegate_;
725 // Our RenderFrameHost and its associated Web UI (if any, will be NULL for
726 // non-WebUI pages). This object is responsible for all communication with
727 // a child RenderFrame instance.
728 // For now, RenderFrameHost keeps a RenderViewHost in its SiteInstance alive.
729 // Eventually, RenderViewHost will be replaced with a page context.
730 scoped_ptr<RenderFrameHostImpl> render_frame_host_;
731 scoped_ptr<WebUIImpl> web_ui_;
733 // A RenderFrameHost used to load a cross-site page. This remains hidden
734 // while a cross-site request is pending until it calls DidNavigate. It may
735 // have an associated Web UI, in which case the Web UI pointer will be non-
736 // NULL.
738 // The |pending_web_ui_| may be non-NULL even when the
739 // |pending_render_frame_host_| is NULL. This will happen when we're
740 // transitioning between two Web UI pages: the RFH won't be swapped, so the
741 // pending pointer will be unused, but there will be a pending Web UI
742 // associated with the navigation.
743 // Note: This is not used in PlzNavigate.
744 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_;
746 // If a pending request needs to be transferred to another process, this
747 // owns the request until it's transferred to the new process, so it will be
748 // cleaned up if the navigation is cancelled. Otherwise, this is NULL.
749 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_;
751 // This is used to temporarily store the NavigationHandle during
752 // transferring navigations. The handle needs to be stored because the old
753 // RenderFrameHost may be discarded before a new RenderFrameHost is created
754 // for the navigation.
755 // PlzNavigate: this will never be set since there are no transferring
756 // navigations in PlzNavigate.
757 scoped_ptr<NavigationHandleImpl> transfer_navigation_handle_;
759 // If either of these is non-NULL, the pending navigation is to a chrome:
760 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is
761 // used for when they reference the same object. If either is non-NULL, the
762 // other should be NULL.
763 // Note: These are not used in PlzNavigate.
764 scoped_ptr<WebUIImpl> pending_web_ui_;
765 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_;
767 class RenderFrameProxyHostMap;
768 scoped_ptr<RenderFrameProxyHostMap> proxy_hosts_;
770 // A list of RenderFrameHosts waiting to shut down after swapping out. We use
771 // a linked list since we expect frequent deletes and no indexed access, and
772 // because sets don't appear to support linked_ptrs.
773 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList;
774 RFHPendingDeleteList pending_delete_hosts_;
776 // The intersitial page currently shown if any, not own by this class
777 // (the InterstitialPage is self-owned, it deletes itself when hidden).
778 InterstitialPageImpl* interstitial_page_;
780 // PlzNavigate
781 // These members store a speculative RenderFrameHost and WebUI. They are
782 // created early in a navigation so a renderer process can be started in
783 // parallel, if needed. This is purely a performance optimization and is not
784 // required for correct behavior. The created RenderFrameHost might be
785 // discarded later on if the final URL's SiteInstance isn't compatible with
786 // what was used to create it.
787 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not
788 // the pending ones.
789 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_;
790 scoped_ptr<WebUIImpl> speculative_web_ui_;
792 // PlzNavigate
793 // If true at navigation commit time the current WebUI will be kept instead of
794 // creating a new one.
795 bool should_reuse_web_ui_;
797 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_;
799 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager);
802 } // namespace content
804 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_