Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / browser / frame_host / render_frame_host_manager.h
blob3cfcab13fb76f4c5d0c9fac377d9287db6340130
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 NavigationRequest;
34 class NavigatorTestWithBrowserSideNavigation;
35 class RenderFrameHost;
36 class RenderFrameHostDelegate;
37 class RenderFrameHostImpl;
38 class RenderFrameHostManagerTest;
39 class RenderFrameProxyHost;
40 class RenderViewHost;
41 class RenderViewHostImpl;
42 class RenderWidgetHostDelegate;
43 class RenderWidgetHostView;
44 class TestWebContents;
45 class WebUIImpl;
46 struct CommonNavigationParams;
47 struct FrameReplicationState;
49 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a
50 // current_frame_host() which is the content currently visible to the user. When
51 // a frame is told to navigate to a different web site (as determined by
52 // SiteInstance), it will replace its current RenderFrameHost with a new
53 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process.
55 // Cross-process navigation works like this:
57 // - RFHM::Navigate determines whether the destination is cross-site, and if so,
58 // it creates a pending_render_frame_host_.
60 // - The pending RFH is created in the "navigations suspended" state, meaning no
61 // navigation messages are sent to its renderer until the beforeunload handler
62 // has a chance to run in the current RFH.
64 // - The current RFH runs its beforeunload handler. If it returns false, we
65 // cancel all the pending logic. Otherwise we allow the pending RFH to send
66 // the navigation request to its renderer.
68 // - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
69 // main resource load from the pending RFH. It creates a
70 // CrossSiteResourceHandler to check whether a process transfer is needed when
71 // the request is ready to commit.
73 // - When RDH receives a response, the MimeTypeResourceHandler determines
74 // whether it is a navigation type that doesn't commit (e.g. download, 204 or
75 // error page). If so, it sends a message to the new renderer causing it to
76 // cancel the request, and the request (e.g. the download) proceeds. In this
77 // case, the pending RFH will never become the current RFH, but it remains
78 // until the next DidNavigate event for this WebContentsImpl.
80 // - After RDH receives a response and determines that it is safe and not a
81 // download, the CrossSiteResourceHandler checks whether a transfer for a
82 // redirect is needed. If so, it pauses the network response and starts an
83 // identical navigation in a new pending RFH. When the identical request is
84 // later received by RDH, the response is transferred and unpaused.
86 // - Otherwise, the network response commits in the pending RFH's renderer,
87 // which sends a DidCommitProvisionalLoad message back to the browser process.
89 // - RFHM::CommitPending makes visible the new RFH, and initiates the unload
90 // handler in the old RFH. The unload handler will complete in the background.
92 // - RenderFrameHostManager may keep the previous RFH alive as a
93 // RenderFrameProxyHost, to be used (for example) if the user goes back. The
94 // process only stays live if another tab is using it, but if so, the existing
95 // frame relationships will be maintained.
96 class CONTENT_EXPORT RenderFrameHostManager {
97 public:
98 // Functions implemented by our owner that we need.
100 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl
101 // that are required to run this class. The design should probably be better
102 // such that these are more clear.
104 // There is additional complexity that some of the functions we need in
105 // WebContentsImpl are inherited and non-virtual. These are named with
106 // "RenderManager" so that the duplicate implementation of them will be clear.
108 // Functions and parameters whose description are prefixed by PlzNavigate are
109 // part of a navigation refactoring project, currently behind the
110 // enable-browser-side-navigation flag. The idea is to move the logic behind
111 // driving navigations from the renderer to the browser.
112 class CONTENT_EXPORT Delegate {
113 public:
114 // Initializes the given renderer if necessary and creates the view ID
115 // corresponding to this view host. If this method is not called and the
116 // process is not shared, then the WebContentsImpl will act as though the
117 // renderer is not running (i.e., it will render "sad tab"). This method is
118 // automatically called from LoadURL. |for_main_frame_navigation| indicates
119 // whether this RenderViewHost is used to render a top-level frame, so the
120 // appropriate RenderWidgetHostView type is used.
121 virtual bool CreateRenderViewForRenderManager(
122 RenderViewHost* render_view_host,
123 int opener_frame_routing_id,
124 int proxy_routing_id,
125 const FrameReplicationState& replicated_frame_state,
126 bool for_main_frame_navigation) = 0;
127 virtual bool CreateRenderFrameForRenderManager(
128 RenderFrameHost* render_frame_host,
129 int parent_routing_id,
130 int previous_sibling_routing_id,
131 int proxy_routing_id) = 0;
132 virtual void BeforeUnloadFiredFromRenderManager(
133 bool proceed, const base::TimeTicks& proceed_time,
134 bool* proceed_to_fire_unload) = 0;
135 virtual void RenderProcessGoneFromRenderManager(
136 RenderViewHost* render_view_host) = 0;
137 virtual void UpdateRenderViewSizeForRenderManager() = 0;
138 virtual void CancelModalDialogsForRenderManager() = 0;
139 virtual void NotifySwappedFromRenderManager(RenderFrameHost* old_host,
140 RenderFrameHost* new_host,
141 bool is_main_frame) = 0;
142 // TODO(nasko): This should be removed once extensions no longer use
143 // NotificationService. See https://crbug.com/462682.
144 virtual void NotifyMainFrameSwappedFromRenderManager(
145 RenderViewHost* old_host,
146 RenderViewHost* new_host) = 0;
147 virtual NavigationControllerImpl&
148 GetControllerForRenderManager() = 0;
150 // Creates a WebUI object for the given URL if one applies. Ownership of the
151 // returned pointer will be passed to the caller. If no WebUI applies,
152 // returns NULL.
153 virtual scoped_ptr<WebUIImpl> CreateWebUIForRenderManager(
154 const GURL& url) = 0;
156 // Returns the navigation entry of the current navigation, or NULL if there
157 // is none.
158 virtual NavigationEntry*
159 GetLastCommittedNavigationEntryForRenderManager() = 0;
161 // Returns true if the location bar should be focused by default rather than
162 // the page contents. The view calls this function when the tab is focused
163 // to see what it should do.
164 virtual bool FocusLocationBarByDefault() = 0;
166 // Focuses the location bar.
167 virtual void SetFocusToLocationBar(bool select_all) = 0;
169 // Returns true if views created for this delegate should be created in a
170 // hidden state.
171 virtual bool IsHidden() = 0;
173 // If the delegate is an inner WebContents, this method returns the
174 // FrameTreeNode ID of the frame in the outer WebContents which hosts
175 // the inner WebContents. Returns FrameTreeNode::kFrameTreeNodeInvalidID
176 // if the delegate does not have an outer WebContents.
177 virtual int GetOuterDelegateFrameTreeNodeID() = 0;
179 protected:
180 virtual ~Delegate() {}
183 // Used with FrameTree::ForEach to delete RenderFrameHosts pending shutdown
184 // from a FrameTreeNode's RenderFrameHostManager. Used during destruction of
185 // WebContentsImpl.
186 static bool ClearRFHsPendingShutdown(FrameTreeNode* node);
188 // Returns true if we are currently in a mode where the swapped out state
189 // should not be used. Currently (as an implementation strategy) swapped out
190 // is forbidden under --site-per-process, but our goal is to eliminate the
191 // mode entirely. In code that deals with the swapped out state, prefer calls
192 // to this function over consulting the switches directly. It will be easier
193 // to grep, and easier to rip out.
195 // TODO(nasko): When swappedout:// is eliminated entirely, this function (and
196 // its equivalent in RenderFrameProxy) should be removed and its callers
197 // cleaned up.
198 static bool IsSwappedOutStateForbidden();
200 // All three delegate pointers must be non-NULL and are not owned by this
201 // class. They must outlive this class. The RenderViewHostDelegate and
202 // RenderWidgetHostDelegate are what will be installed into all
203 // RenderViewHosts that are created.
205 // You must call Init() before using this class.
206 RenderFrameHostManager(
207 FrameTreeNode* frame_tree_node,
208 RenderFrameHostDelegate* render_frame_delegate,
209 RenderViewHostDelegate* render_view_delegate,
210 RenderWidgetHostDelegate* render_widget_delegate,
211 Delegate* delegate);
212 ~RenderFrameHostManager();
214 // For arguments, see WebContentsImpl constructor.
215 void Init(BrowserContext* browser_context,
216 SiteInstance* site_instance,
217 int view_routing_id,
218 int frame_routing_id);
220 // Returns the currently active RenderFrameHost.
222 // This will be non-NULL between Init() and Shutdown(). You may want to NULL
223 // check it in many cases, however. Windows can send us messages during the
224 // destruction process after it has been shut down.
225 RenderFrameHostImpl* current_frame_host() const {
226 return render_frame_host_.get();
229 // TODO(creis): Remove this when we no longer use RVH for navigation.
230 RenderViewHostImpl* current_host() const;
232 // Returns the view associated with the current RenderViewHost, or NULL if
233 // there is no current one.
234 RenderWidgetHostView* GetRenderWidgetHostView() const;
236 // Returns whether this manager belongs to a FrameTreeNode that is a main
237 // frame in an inner WebContents.
238 // TODO(lazyboy): Make this work correctly for subframes inside inner
239 // WebContents too.
240 bool ForInnerDelegate();
242 // Returns the RenderWidgetHost of the outer WebContents (if any) that can be
243 // used to fetch the last keyboard event.
244 // TODO(lazyboy): This can be removed once input events are sent directly to
245 // remote frames.
246 RenderWidgetHostImpl* GetOuterRenderWidgetHostForKeyboardInput();
248 RenderFrameProxyHost* GetProxyToParent();
250 // Returns the proxy to inner WebContents in the outer WebContents's
251 // SiteInstance. Returns nullptr if this WebContents isn't part of inner/outer
252 // relationship.
253 RenderFrameProxyHost* GetProxyToOuterDelegate();
255 // Removes the FrameTreeNode in the outer WebContents that represents this
256 // FrameTreeNode.
257 // TODO(lazyboy): This does not belong to RenderFrameHostManager, move it to
258 // somehwere else.
259 void RemoveOuterDelegateFrame();
261 // Returns the pending RenderFrameHost, or NULL if there is no pending one.
262 RenderFrameHostImpl* pending_frame_host() const {
263 return pending_render_frame_host_.get();
266 // Returns the speculative RenderFrameHost, or null if there is no speculative
267 // one.
268 RenderFrameHostImpl* speculative_frame_host() const {
269 return speculative_render_frame_host_.get();
272 // TODO(creis): Remove this when we no longer use RVH for navigation.
273 RenderViewHostImpl* pending_render_view_host() const;
275 // Returns the current committed Web UI or NULL if none applies.
276 WebUIImpl* web_ui() const { return web_ui_.get(); }
278 // Returns the Web UI for the pending navigation, or NULL of none applies.
279 WebUIImpl* pending_web_ui() const {
280 return pending_web_ui_.get() ? pending_web_ui_.get() :
281 pending_and_current_web_ui_.get();
284 // PlzNavigate
285 // Returns the speculative WebUI for the navigation (a newly created one or
286 // the current one if it should be reused). If none is set returns nullptr.
287 WebUIImpl* speculative_web_ui() const {
288 return should_reuse_web_ui_ ? web_ui_.get() : speculative_web_ui_.get();
291 // Called when we want to instruct the renderer to navigate to the given
292 // navigation entry. It may create a new RenderFrameHost or re-use an existing
293 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one
294 // could not be created. |dest_url| takes precedence over the |frame_entry|'s
295 // url (this is necessary because ReloadOriginalRequest navigates to a
296 // different URL than the last committed entry, without modifying it).
297 RenderFrameHostImpl* Navigate(const GURL& dest_url,
298 const FrameNavigationEntry& frame_entry,
299 const NavigationEntryImpl& entry);
301 // Instructs the various live views to stop. Called when the user directed the
302 // page to stop loading.
303 void Stop();
305 // Notifies the regular and pending RenderViewHosts that a load is or is not
306 // happening. Even though the message is only for one of them, we don't know
307 // which one so we tell both.
308 void SetIsLoading(bool is_loading);
310 // Whether to close the tab or not when there is a hang during an unload
311 // handler. If we are mid-crosssite navigation, then we should proceed
312 // with the navigation instead of closing the tab.
313 bool ShouldCloseTabOnUnresponsiveRenderer();
315 // Confirms whether we should close the page or navigate away. This is called
316 // before a cross-site request or before a tab/window is closed (as indicated
317 // by the first parameter) to allow the appropriate renderer to approve or
318 // deny the request. |proceed| indicates whether the user chose to proceed.
319 // |proceed_time| is the time when the request was allowed to proceed.
320 void OnBeforeUnloadACK(bool for_cross_site_transition,
321 bool proceed,
322 const base::TimeTicks& proceed_time);
324 // The |pending_render_frame_host| is ready to commit a page. We should
325 // ensure that the old RenderFrameHost runs its unload handler first and
326 // determine whether a RenderFrameHost transfer is needed.
327 // |cross_site_transferring_request| is NULL if a request is not being
328 // transferred between renderers.
329 void OnCrossSiteResponse(
330 RenderFrameHostImpl* pending_render_frame_host,
331 const GlobalRequestID& global_request_id,
332 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request,
333 const std::vector<GURL>& transfer_url_chain,
334 const Referrer& referrer,
335 ui::PageTransition page_transition,
336 bool should_replace_current_entry);
338 // Called when a renderer's frame navigates.
339 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host,
340 bool was_caused_by_user_gesture);
342 // Called when a renderer sets its opener to null.
343 void DidDisownOpener(RenderFrameHost* render_frame_host);
345 // Sets the pending Web UI for the pending navigation, ensuring that the
346 // bindings are appropriate compared to |bindings|.
347 void SetPendingWebUI(const GURL& url, int bindings);
349 // Creates and initializes a RenderFrameHost. The |web_ui| is an optional
350 // input parameter used to double check bindings when swapping back in a
351 // previously existing RenderFrameHost. If |flags| has the
352 // CREATE_RF_SWAPPED_OUT bit set from the CreateRenderFrameFlags enum, it will
353 // initially be placed on the swapped out hosts list. If |view_routing_id_ptr|
354 // is not nullptr it will be set to the routing id of the view associated with
355 // the frame.
356 scoped_ptr<RenderFrameHostImpl> CreateRenderFrame(SiteInstance* instance,
357 WebUIImpl* web_ui,
358 int flags,
359 int* view_routing_id_ptr);
361 // Helper method to create and initialize a RenderFrameProxyHost and return
362 // its routing id.
363 int CreateRenderFrameProxy(SiteInstance* instance);
365 // Creates proxies for a new child frame at FrameTreeNode |child| in all
366 // SiteInstances for which the current frame has proxies. This method is
367 // called on the parent of a new child frame before the child leaves the
368 // SiteInstance.
369 void CreateProxiesForChildFrame(FrameTreeNode* child);
371 // Sets the passed passed interstitial as the currently showing interstitial.
372 // |interstitial_page| should be non NULL (use the remove_interstitial_page
373 // method to unset the interstitial) and no interstitial page should be set
374 // when there is already a non NULL interstitial page set.
375 void set_interstitial_page(InterstitialPageImpl* interstitial_page) {
376 DCHECK(!interstitial_page_ && interstitial_page);
377 interstitial_page_ = interstitial_page;
380 // Unsets the currently showing interstitial.
381 void remove_interstitial_page() {
382 DCHECK(interstitial_page_);
383 interstitial_page_ = NULL;
386 // Returns the currently showing interstitial, NULL if no interstitial is
387 // showing.
388 InterstitialPageImpl* interstitial_page() const { return interstitial_page_; }
390 // Returns whether the given RenderFrameHost (or its associated
391 // RenderViewHost) is on the list of swapped out RenderFrameHosts.
392 bool IsRVHOnSwappedOutList(RenderViewHostImpl* rvh) const;
393 bool IsOnSwappedOutList(RenderFrameHostImpl* rfh) const;
395 // Returns the swapped out RenderViewHost for the given SiteInstance, if any.
396 // This method is *deprecated* and GetRenderFrameProxyHost should be used.
397 RenderViewHostImpl* GetSwappedOutRenderViewHost(SiteInstance* instance) const;
399 // Returns the RenderFrameProxyHost for the given SiteInstance, if any.
400 RenderFrameProxyHost* GetRenderFrameProxyHost(
401 SiteInstance* instance) const;
403 // Returns whether |render_frame_host| is on the pending deletion list.
404 bool IsPendingDeletion(RenderFrameHostImpl* render_frame_host);
406 // If |render_frame_host| is on the pending deletion list, this deletes it.
407 // Returns whether it was deleted.
408 bool DeleteFromPendingList(RenderFrameHostImpl* render_frame_host);
410 // Deletes any proxy hosts associated with this node. Used during destruction
411 // of WebContentsImpl.
412 void ResetProxyHosts();
414 // Returns the routing id for a RenderFrameHost or RenderFrameProxyHost
415 // that has the given SiteInstance and is associated with this
416 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found.
417 int GetRoutingIdForSiteInstance(SiteInstance* site_instance);
419 // PlzNavigate
420 // Notifies the RenderFrameHostManager that a new NavigationRequest has been
421 // created and set in the FrameTreeNode so that it can speculatively create a
422 // new RenderFrameHost (and potentially a new process) if needed.
423 void DidCreateNavigationRequest(const NavigationRequest& request);
425 // PlzNavigate
426 // Called (possibly several times) during a navigation to select or create an
427 // appropriate RenderFrameHost for the provided URL. The returned pointer will
428 // be for the current or the speculative RenderFrameHost and the instance is
429 // owned by this manager.
430 RenderFrameHostImpl* GetFrameHostForNavigation(
431 const NavigationRequest& request);
433 // PlzNavigate
434 // Clean up any state for any ongoing navigation.
435 void CleanUpNavigation();
437 // PlzNavigate
438 // Clears the speculative members, returning the RenderFrameHost to the caller
439 // for disposal.
440 scoped_ptr<RenderFrameHostImpl> UnsetSpeculativeRenderFrameHost();
442 // Notification methods to tell this RenderFrameHostManager that the frame it
443 // is responsible for has started or stopped loading a document.
444 void OnDidStartLoading();
445 void OnDidStopLoading();
447 // Send updated frame name to all frame proxies when the frame changes its
448 // window.name property.
449 void OnDidUpdateName(const std::string& name);
451 // Send updated origin to all frame proxies when the frame navigates to a new
452 // origin.
453 void OnDidUpdateOrigin(const url::Origin& origin);
455 void EnsureRenderViewInitialized(RenderViewHostImpl* render_view_host,
456 SiteInstance* instance);
458 // Recursively creates swapped out RenderViews and RenderFrameProxies for
459 // this frame's FrameTree and for its opener chain in the given SiteInstance.
460 // This allows other tabs to send cross-process JavaScript calls to their
461 // opener(s) and to any other frames in the opener's FrameTree (e.g.,
462 // supporting calls like window.opener.opener.frames[x][y]).
463 void CreateOpenerProxies(SiteInstance* instance);
465 // Ensure that this frame has proxies in all SiteInstances that can discover
466 // this frame by name (e.g., via window.open("", "frame_name")). See
467 // https://crbug.com/511474.
468 void CreateProxiesForNewNamedFrame();
470 // Returns a routing ID for the current FrameTreeNode's opener node in the
471 // given SiteInstance. May return a routing ID of either a RenderFrameHost
472 // (if opener's current or pending RFH has SiteInstance |instance|) or a
473 // RenderFrameProxyHost. Returns MSG_ROUTING_NONE if there is no opener, or
474 // if the opener node doesn't have a proxy for |instance|.
475 int GetOpenerRoutingID(SiteInstance* instance);
477 // Called on the RFHM of the inner WebContents to create a
478 // RenderFrameProxyHost in its outer WebContents's SiteInstance,
479 // |outer_contents_site_instance|. The frame in outer WebContents that is
480 // hosting the inner WebContents is |render_frame_host|, and the frame will
481 // be swapped out with the proxy.
482 void CreateOuterDelegateProxy(SiteInstance* outer_contents_site_instance,
483 RenderFrameHostImpl* render_frame_host);
485 // Sets the child RenderWidgetHostView for this frame, which must be part of
486 // an inner WebContents.
487 void SetRWHViewForInnerContents(RenderWidgetHostView* child_rwhv);
489 // Returns a copy of the map of proxy hosts. The keys are SiteInstance IDs,
490 // the values are RenderFrameProxyHosts.
491 std::map<int, RenderFrameProxyHost*> GetAllProxyHostsForTesting();
493 private:
494 friend class NavigatorTestWithBrowserSideNavigation;
495 friend class RenderFrameHostManagerTest;
496 friend class TestWebContents;
498 // Stores information regarding a SiteInstance targeted at a specific URL to
499 // allow for comparisons without having to actually create new instances. It
500 // can point to an existing one or store the details needed to create a new
501 // one.
502 struct CONTENT_EXPORT SiteInstanceDescriptor {
503 explicit SiteInstanceDescriptor(content::SiteInstance* site_instance)
504 : existing_site_instance(site_instance),
505 new_is_related_to_current(false) {}
507 SiteInstanceDescriptor(BrowserContext* browser_context,
508 GURL dest_url,
509 bool related_to_current);
511 // Set with an existing SiteInstance to be reused.
512 content::SiteInstance* existing_site_instance;
514 // In case |existing_site_instance| is null, specify a new site URL.
515 GURL new_site_url;
517 // In case |existing_site_instance| is null, specify if the new site should
518 // be created in a new BrowsingInstance or not.
519 bool new_is_related_to_current;
522 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a
523 // FrameTreeNode's RenderFrameHostManager.
524 static bool ClearProxiesInSiteInstance(int32 site_instance_id,
525 FrameTreeNode* node);
526 // Used with FrameTree::ForEach to reset initialized state of
527 // RenderFrameProxyHosts from a FrameTreeNode's RenderFrameHostManager.
528 static bool ResetProxiesInSiteInstance(int32 site_instance_id,
529 FrameTreeNode* node);
531 // Returns whether this tab should transition to a new renderer for
532 // cross-site URLs. Enabled unless we see the --process-per-tab command line
533 // switch. Can be overridden in unit tests.
534 bool ShouldTransitionCrossSite();
536 // Returns true if for the navigation from |current_effective_url| to
537 // |new_effective_url|, a new SiteInstance and BrowsingInstance should be
538 // created (even if we are in a process model that doesn't usually swap).
539 // This forces a process swap and severs script connections with existing
540 // tabs. Cases where this can happen include transitions between WebUI and
541 // regular web pages. |new_site_instance| may be null.
542 // If there is no current NavigationEntry, then |current_is_view_source_mode|
543 // should be the same as |new_is_view_source_mode|.
545 // We use the effective URL here, since that's what is used in the
546 // SiteInstance's site and when we later call IsSameWebSite. If there is no
547 // current NavigationEntry, check the current SiteInstance's site, which might
548 // already be committed to a Web UI URL (such as the NTP).
549 bool ShouldSwapBrowsingInstancesForNavigation(
550 const GURL& current_effective_url,
551 bool current_is_view_source_mode,
552 SiteInstance* new_site_instance,
553 const GURL& new_effective_url,
554 bool new_is_view_source_mode) const;
556 // Creates a new Web UI, ensuring that the bindings are appropriate compared
557 // to |bindings|.
558 scoped_ptr<WebUIImpl> CreateWebUI(const GURL& url, int bindings);
560 // Returns true if it is safe to reuse the current WebUI when navigating from
561 // |current_entry| to |new_url|.
562 bool ShouldReuseWebUI(
563 const NavigationEntry* current_entry,
564 const GURL& new_url) const;
566 // Returns the SiteInstance to use for the navigation.
567 SiteInstance* GetSiteInstanceForNavigation(const GURL& dest_url,
568 SiteInstance* source_instance,
569 SiteInstance* dest_instance,
570 SiteInstance* candidate_instance,
571 ui::PageTransition transition,
572 bool dest_is_restore,
573 bool dest_is_view_source_mode);
575 // Returns a descriptor of the appropriate SiteInstance object for the given
576 // |dest_url|, possibly reusing the current, source or destination
577 // SiteInstance. The actual SiteInstance can then be obtained calling
578 // ConvertToSiteInstance with the descriptor.
580 // |source_instance| is the SiteInstance of the frame that initiated the
581 // navigation. |current_instance| is the SiteInstance of the frame that is
582 // currently navigating. |dest_instance| is a predetermined SiteInstance that
583 // will be used if not null.
584 // For example, if you have a parent frame A, which has a child frame B, and
585 // A is trying to change the src attribute of B, this will cause a navigation
586 // where the source SiteInstance is A and B is the current SiteInstance.
588 // This is a helper function for GetSiteInstanceForNavigation.
589 SiteInstanceDescriptor DetermineSiteInstanceForURL(
590 const GURL& dest_url,
591 SiteInstance* source_instance,
592 SiteInstance* current_instance,
593 SiteInstance* dest_instance,
594 ui::PageTransition transition,
595 bool dest_is_restore,
596 bool dest_is_view_source_mode,
597 bool force_browsing_instance_swap);
599 // Converts a SiteInstanceDescriptor to the actual SiteInstance it describes.
600 // If a |candidate_instance| is provided (is not nullptr) and it matches the
601 // description, it is returned as is.
602 SiteInstance* ConvertToSiteInstance(const SiteInstanceDescriptor& descriptor,
603 SiteInstance* candidate_instance);
605 // Determines the appropriate url to use as the current url for SiteInstance
606 // selection.
607 const GURL& GetCurrentURLForSiteInstance(
608 SiteInstance* current_instance,
609 NavigationEntry* current_entry);
611 // Creates a new RenderFrameHostImpl for the |new_instance| and assign it to
612 // |pending_render_frame_host_| while respecting the opener route if needed
613 // and stores it in pending_render_frame_host_.
614 void CreatePendingRenderFrameHost(SiteInstance* old_instance,
615 SiteInstance* new_instance,
616 bool is_main_frame);
618 // Ensure that we have created all needed proxies for a new RFH with
619 // SiteInstance |new_instance|: (1) create swapped-out RVHs and proxies for
620 // the new RFH's opener chain if we are staying in the same BrowsingInstance;
621 // (2) Create proxies for the new RFH's SiteInstance in its own frame tree;
622 // (3) set any additional flags for the new RenderFrame with
623 // |create_render_frame_flags|.
624 void CreateProxiesForNewRenderFrameHost(SiteInstance* old_instance,
625 SiteInstance* new_instance,
626 int* create_render_frame_flags);
628 // Create swapped out RenderViews and RenderFrameProxies in the given
629 // SiteInstance for all frames on the opener chain of this frame. Same as
630 // CreateOpenerProxies, but starts from this frame's opener, calling
631 // CreateOpenerProxies on it if it exists and returning otherwise.
632 void CreateOpenerProxiesIfNeeded(SiteInstance* instance);
634 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
635 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance,
636 int view_routing_id,
637 int frame_routing_id,
638 int flags);
640 // PlzNavigate
641 // Creates and initializes a speculative RenderFrameHost and/or WebUI for an
642 // ongoing navigation. They might be destroyed and re-created later if the
643 // navigation is redirected to a different SiteInstance.
644 bool CreateSpeculativeRenderFrameHost(const GURL& url,
645 SiteInstance* old_instance,
646 SiteInstance* new_instance,
647 int bindings);
649 // Sets up the necessary state for a new RenderViewHost. Creates a
650 // RenderFrameProxy in the target renderer process with the given
651 // |proxy_routing_id|, which is used to route IPC messages when in swapped
652 // out state. Returns early if the RenderViewHost has already been
653 // initialized for another RenderFrameHost.
654 bool InitRenderView(RenderViewHostImpl* render_view_host,
655 int proxy_routing_id,
656 bool for_main_frame_navigation);
658 // Initialization for RenderFrameHost uses the same sequence as InitRenderView
659 // above.
660 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host);
662 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
663 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
664 // since there could be Web UI switching as well. Call this for every commit.
665 // If PlzNavigate is enabled the method will set the speculative (not pending)
666 // RenderFrameHost to be the active one.
667 void CommitPending();
669 // Helper to call CommitPending() in all necessary cases.
670 void CommitPendingIfNecessary(RenderFrameHostImpl* render_frame_host,
671 bool was_caused_by_user_gesture);
673 // Commits any pending sandbox flag updates when the renderer's frame
674 // navigates.
675 void CommitPendingSandboxFlags();
677 // Runs the unload handler in the old RenderFrameHost, after the new
678 // RenderFrameHost has committed. |old_render_frame_host| will either be
679 // deleted or put on the pending delete list during this call.
680 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host);
682 // Discards a RenderFrameHost that was never made active (for active ones
683 // SwapOutOldFrame is used instead).
684 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host);
686 // Holds |render_frame_host| until it can be deleted when its swap out ACK
687 // arrives.
688 void MoveToPendingDeleteHosts(
689 scoped_ptr<RenderFrameHostImpl> render_frame_host);
691 // If |render_frame_host| is the last remaining active frame in its
692 // SiteInstance, this will shutdown all the RenderFrameProxyHosts in the
693 // SiteInstance. This is appropriate if |render_frame_host| is about to be
694 // destroyed.
695 void ShutdownProxiesIfLastActiveFrameInSiteInstance(
696 RenderFrameHostImpl* render_frame_host);
698 // Helper method to terminate the pending RenderFrameHost. The frame may be
699 // deleted immediately, or it may be kept around in hopes of later reuse.
700 void CancelPending();
702 // Clears pending_render_frame_host_, returning it to the caller for disposal.
703 scoped_ptr<RenderFrameHostImpl> UnsetPendingRenderFrameHost();
705 // Helper method to set the active RenderFrameHost. Returns the old
706 // RenderFrameHost and updates counts.
707 scoped_ptr<RenderFrameHostImpl> SetRenderFrameHost(
708 scoped_ptr<RenderFrameHostImpl> render_frame_host);
710 RenderFrameHostImpl* UpdateStateForNavigate(
711 const GURL& dest_url,
712 SiteInstance* source_instance,
713 SiteInstance* dest_instance,
714 ui::PageTransition transition,
715 bool dest_is_restore,
716 bool dest_is_view_source_mode,
717 const GlobalRequestID& transferred_request_id,
718 int bindings);
720 // Called when a renderer process is starting to close. We should not
721 // schedule new navigations in its swapped out RenderFrameHosts after this.
722 void RendererProcessClosing(RenderProcessHost* render_process_host);
724 // For use in creating RenderFrameHosts.
725 FrameTreeNode* frame_tree_node_;
727 // Our delegate, not owned by us. Guaranteed non-NULL.
728 Delegate* delegate_;
730 // Implemented by the owner of this class. These delegates are installed into
731 // all the RenderFrameHosts that we create.
732 RenderFrameHostDelegate* render_frame_delegate_;
733 RenderViewHostDelegate* render_view_delegate_;
734 RenderWidgetHostDelegate* render_widget_delegate_;
736 // Our RenderFrameHost and its associated Web UI (if any, will be NULL for
737 // non-WebUI pages). This object is responsible for all communication with
738 // a child RenderFrame instance.
739 // For now, RenderFrameHost keeps a RenderViewHost in its SiteInstance alive.
740 // Eventually, RenderViewHost will be replaced with a page context.
741 scoped_ptr<RenderFrameHostImpl> render_frame_host_;
742 scoped_ptr<WebUIImpl> web_ui_;
744 // A RenderFrameHost used to load a cross-site page. This remains hidden
745 // while a cross-site request is pending until it calls DidNavigate. It may
746 // have an associated Web UI, in which case the Web UI pointer will be non-
747 // NULL.
749 // The |pending_web_ui_| may be non-NULL even when the
750 // |pending_render_frame_host_| is NULL. This will happen when we're
751 // transitioning between two Web UI pages: the RFH won't be swapped, so the
752 // pending pointer will be unused, but there will be a pending Web UI
753 // associated with the navigation.
754 // Note: This is not used in PlzNavigate.
755 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_;
757 // If a pending request needs to be transferred to another process, this
758 // owns the request until it's transferred to the new process, so it will be
759 // cleaned up if the navigation is cancelled. Otherwise, this is NULL.
760 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_;
762 // If either of these is non-NULL, the pending navigation is to a chrome:
763 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is
764 // used for when they reference the same object. If either is non-NULL, the
765 // other should be NULL.
766 // Note: These are not used in PlzNavigate.
767 scoped_ptr<WebUIImpl> pending_web_ui_;
768 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_;
770 class RenderFrameProxyHostMap;
771 scoped_ptr<RenderFrameProxyHostMap> proxy_hosts_;
773 // A list of RenderFrameHosts waiting to shut down after swapping out. We use
774 // a linked list since we expect frequent deletes and no indexed access, and
775 // because sets don't appear to support linked_ptrs.
776 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList;
777 RFHPendingDeleteList pending_delete_hosts_;
779 // The intersitial page currently shown if any, not own by this class
780 // (the InterstitialPage is self-owned, it deletes itself when hidden).
781 InterstitialPageImpl* interstitial_page_;
783 // PlzNavigate
784 // These members store a speculative RenderFrameHost and WebUI. They are
785 // created early in a navigation so a renderer process can be started in
786 // parallel, if needed. This is purely a performance optimization and is not
787 // required for correct behavior. The created RenderFrameHost might be
788 // discarded later on if the final URL's SiteInstance isn't compatible with
789 // what was used to create it.
790 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not
791 // the pending ones.
792 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_;
793 scoped_ptr<WebUIImpl> speculative_web_ui_;
795 // PlzNavigate
796 // If true at navigation commit time the current WebUI will be kept instead of
797 // creating a new one.
798 bool should_reuse_web_ui_;
800 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_;
802 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager);
805 } // namespace content
807 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_