OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
| 9 #include <map> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "content/browser/renderer_host/render_view_host_delegate.h" | 15 #include "content/browser/renderer_host/render_view_host_delegate.h" |
15 #include "content/browser/site_instance_impl.h" | 16 #include "content/browser/site_instance_impl.h" |
16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
17 #include "content/public/browser/global_request_id.h" | 18 #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" | 19 #include "content/public/common/referrer.h" |
21 #include "ui/base/page_transition_types.h" | 20 #include "ui/base/page_transition_types.h" |
22 #include "url/deprecated_serialized_origin.h" | 21 #include "url/deprecated_serialized_origin.h" |
23 | 22 |
24 namespace content { | 23 namespace content { |
25 class BrowserContext; | 24 class BrowserContext; |
26 class CrossProcessFrameConnector; | 25 class CrossProcessFrameConnector; |
27 class CrossSiteTransferringRequest; | 26 class CrossSiteTransferringRequest; |
28 class FrameNavigationEntry; | 27 class FrameNavigationEntry; |
29 class FrameTreeNode; | 28 class FrameTreeNode; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // - Otherwise, the network response commits in the pending RFH's renderer, | 86 // - Otherwise, the network response commits in the pending RFH's renderer, |
88 // which sends a DidCommitProvisionalLoad message back to the browser process. | 87 // which sends a DidCommitProvisionalLoad message back to the browser process. |
89 // | 88 // |
90 // - RFHM::CommitPending makes visible the new RFH, and initiates the unload | 89 // - 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. | 90 // handler in the old RFH. The unload handler will complete in the background. |
92 // | 91 // |
93 // - RenderFrameHostManager may keep the previous RFH alive as a | 92 // - RenderFrameHostManager may keep the previous RFH alive as a |
94 // RenderFrameProxyHost, to be used (for example) if the user goes back. The | 93 // 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 | 94 // process only stays live if another tab is using it, but if so, the existing |
96 // frame relationships will be maintained. | 95 // frame relationships will be maintained. |
97 class CONTENT_EXPORT RenderFrameHostManager : public NotificationObserver { | 96 class CONTENT_EXPORT RenderFrameHostManager { |
98 public: | 97 public: |
99 // Functions implemented by our owner that we need. | 98 // Functions implemented by our owner that we need. |
100 // | 99 // |
101 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl | 100 // 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 | 101 // that are required to run this class. The design should probably be better |
103 // such that these are more clear. | 102 // such that these are more clear. |
104 // | 103 // |
105 // There is additional complexity that some of the functions we need in | 104 // There is additional complexity that some of the functions we need in |
106 // WebContentsImpl are inherited and non-virtual. These are named with | 105 // WebContentsImpl are inherited and non-virtual. These are named with |
107 // "RenderManager" so that the duplicate implementation of them will be clear. | 106 // "RenderManager" so that the duplicate implementation of them will be clear. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // mode entirely. In code that deals with the swapped out state, prefer calls | 191 // mode entirely. In code that deals with the swapped out state, prefer calls |
193 // to this function over consulting the switches directly. It will be easier | 192 // to this function over consulting the switches directly. It will be easier |
194 // to grep, and easier to rip out. | 193 // to grep, and easier to rip out. |
195 // | 194 // |
196 // TODO(nasko): When swappedout:// is eliminated entirely, this function (and | 195 // TODO(nasko): When swappedout:// is eliminated entirely, this function (and |
197 // its equivalent in RenderFrameProxy) should be removed and its callers | 196 // its equivalent in RenderFrameProxy) should be removed and its callers |
198 // cleaned up. | 197 // cleaned up. |
199 static bool IsSwappedOutStateForbidden(); | 198 static bool IsSwappedOutStateForbidden(); |
200 | 199 |
201 // All three delegate pointers must be non-NULL and are not owned by this | 200 // All three delegate pointers must be non-NULL and are not owned by this |
202 // class. They must outlive this class. The RenderViewHostDelegate and | 201 // class. They must outlive this class. The RenderViewHostDelegate and |
203 // RenderWidgetHostDelegate are what will be installed into all | 202 // RenderWidgetHostDelegate are what will be installed into all |
204 // RenderViewHosts that are created. | 203 // RenderViewHosts that are created. |
205 // | 204 // |
206 // You must call Init() before using this class. | 205 // You must call Init() before using this class. |
207 RenderFrameHostManager( | 206 RenderFrameHostManager( |
208 FrameTreeNode* frame_tree_node, | 207 FrameTreeNode* frame_tree_node, |
209 RenderFrameHostDelegate* render_frame_delegate, | 208 RenderFrameHostDelegate* render_frame_delegate, |
210 RenderViewHostDelegate* render_view_delegate, | 209 RenderViewHostDelegate* render_view_delegate, |
211 RenderWidgetHostDelegate* render_widget_delegate, | 210 RenderWidgetHostDelegate* render_widget_delegate, |
212 Delegate* delegate); | 211 Delegate* delegate); |
213 ~RenderFrameHostManager() override; | 212 ~RenderFrameHostManager(); |
214 | 213 |
215 // For arguments, see WebContentsImpl constructor. | 214 // For arguments, see WebContentsImpl constructor. |
216 void Init(BrowserContext* browser_context, | 215 void Init(BrowserContext* browser_context, |
217 SiteInstance* site_instance, | 216 SiteInstance* site_instance, |
218 int view_routing_id, | 217 int view_routing_id, |
219 int frame_routing_id); | 218 int frame_routing_id); |
220 | 219 |
221 // Returns the currently active RenderFrameHost. | 220 // Returns the currently active RenderFrameHost. |
222 // | 221 // |
223 // This will be non-NULL between Init() and Shutdown(). You may want to NULL | 222 // This will be non-NULL between Init() and Shutdown(). You may want to NULL |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 // Unsets the currently showing interstitial. | 380 // Unsets the currently showing interstitial. |
382 void remove_interstitial_page() { | 381 void remove_interstitial_page() { |
383 DCHECK(interstitial_page_); | 382 DCHECK(interstitial_page_); |
384 interstitial_page_ = NULL; | 383 interstitial_page_ = NULL; |
385 } | 384 } |
386 | 385 |
387 // Returns the currently showing interstitial, NULL if no interstitial is | 386 // Returns the currently showing interstitial, NULL if no interstitial is |
388 // showing. | 387 // showing. |
389 InterstitialPageImpl* interstitial_page() const { return interstitial_page_; } | 388 InterstitialPageImpl* interstitial_page() const { return interstitial_page_; } |
390 | 389 |
391 // NotificationObserver implementation. | |
392 void Observe(int type, | |
393 const NotificationSource& source, | |
394 const NotificationDetails& details) override; | |
395 | |
396 // Returns whether the given RenderFrameHost (or its associated | 390 // Returns whether the given RenderFrameHost (or its associated |
397 // RenderViewHost) is on the list of swapped out RenderFrameHosts. | 391 // RenderViewHost) is on the list of swapped out RenderFrameHosts. |
398 bool IsRVHOnSwappedOutList(RenderViewHostImpl* rvh) const; | 392 bool IsRVHOnSwappedOutList(RenderViewHostImpl* rvh) const; |
399 bool IsOnSwappedOutList(RenderFrameHostImpl* rfh) const; | 393 bool IsOnSwappedOutList(RenderFrameHostImpl* rfh) const; |
400 | 394 |
401 // Returns the swapped out RenderViewHost or RenderFrameHost for the given | 395 // Returns the swapped out RenderViewHost for the given SiteInstance, if any. |
402 // SiteInstance, if any. This method is *deprecated* and | 396 // This method is *deprecated* and GetRenderFrameProxyHost should be used. |
403 // GetRenderFrameProxyHost should be used. | |
404 RenderViewHostImpl* GetSwappedOutRenderViewHost(SiteInstance* instance) const; | 397 RenderViewHostImpl* GetSwappedOutRenderViewHost(SiteInstance* instance) const; |
| 398 |
| 399 // Returns the RenderFrameProxyHost for the given SiteInstance, if any. |
405 RenderFrameProxyHost* GetRenderFrameProxyHost( | 400 RenderFrameProxyHost* GetRenderFrameProxyHost( |
406 SiteInstance* instance) const; | 401 SiteInstance* instance) const; |
407 | 402 |
408 // Returns whether |render_frame_host| is on the pending deletion list. | 403 // Returns whether |render_frame_host| is on the pending deletion list. |
409 bool IsPendingDeletion(RenderFrameHostImpl* render_frame_host); | 404 bool IsPendingDeletion(RenderFrameHostImpl* render_frame_host); |
410 | 405 |
411 // If |render_frame_host| is on the pending deletion list, this deletes it. | 406 // If |render_frame_host| is on the pending deletion list, this deletes it. |
412 // Returns whether it was deleted. | 407 // Returns whether it was deleted. |
413 bool DeleteFromPendingList(RenderFrameHostImpl* render_frame_host); | 408 bool DeleteFromPendingList(RenderFrameHostImpl* render_frame_host); |
414 | 409 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 // |outer_contents_site_instance|. The frame in outer WebContents that is | 474 // |outer_contents_site_instance|. The frame in outer WebContents that is |
480 // hosting the inner WebContents is |render_frame_host|, and the frame will | 475 // hosting the inner WebContents is |render_frame_host|, and the frame will |
481 // be swapped out with the proxy. | 476 // be swapped out with the proxy. |
482 void CreateOuterDelegateProxy(SiteInstance* outer_contents_site_instance, | 477 void CreateOuterDelegateProxy(SiteInstance* outer_contents_site_instance, |
483 RenderFrameHostImpl* render_frame_host); | 478 RenderFrameHostImpl* render_frame_host); |
484 | 479 |
485 // Sets the child RenderWidgetHostView for this frame, which must be part of | 480 // Sets the child RenderWidgetHostView for this frame, which must be part of |
486 // an inner WebContents. | 481 // an inner WebContents. |
487 void SetRWHViewForInnerContents(RenderWidgetHostView* child_rwhv); | 482 void SetRWHViewForInnerContents(RenderWidgetHostView* child_rwhv); |
488 | 483 |
| 484 // Returns a copy of the map of proxy hosts. The keys are SiteInstance IDs, |
| 485 // the values are RenderFrameProxyHosts. |
| 486 std::map<int, RenderFrameProxyHost*> GetAllProxyHostsForTesting(); |
| 487 |
489 private: | 488 private: |
490 friend class FrameTreeVisualizer; | |
491 friend class NavigatorTestWithBrowserSideNavigation; | 489 friend class NavigatorTestWithBrowserSideNavigation; |
492 friend class RenderFrameHostManagerTest; | 490 friend class RenderFrameHostManagerTest; |
493 friend class TestWebContents; | 491 friend class TestWebContents; |
494 | 492 |
495 // Stores information regarding a SiteInstance targeted at a specific URL to | 493 // Stores information regarding a SiteInstance targeted at a specific URL to |
496 // allow for comparisons without having to actually create new instances. It | 494 // allow for comparisons without having to actually create new instances. It |
497 // can point to an existing one or store the details needed to create a new | 495 // can point to an existing one or store the details needed to create a new |
498 // one. | 496 // one. |
499 struct CONTENT_EXPORT SiteInstanceDescriptor { | 497 struct CONTENT_EXPORT SiteInstanceDescriptor { |
500 explicit SiteInstanceDescriptor(content::SiteInstance* site_instance) | 498 explicit SiteInstanceDescriptor(content::SiteInstance* site_instance) |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 ui::PageTransition transition, | 709 ui::PageTransition transition, |
712 bool dest_is_restore, | 710 bool dest_is_restore, |
713 bool dest_is_view_source_mode, | 711 bool dest_is_view_source_mode, |
714 const GlobalRequestID& transferred_request_id, | 712 const GlobalRequestID& transferred_request_id, |
715 int bindings); | 713 int bindings); |
716 | 714 |
717 // Called when a renderer process is starting to close. We should not | 715 // Called when a renderer process is starting to close. We should not |
718 // schedule new navigations in its swapped out RenderFrameHosts after this. | 716 // schedule new navigations in its swapped out RenderFrameHosts after this. |
719 void RendererProcessClosing(RenderProcessHost* render_process_host); | 717 void RendererProcessClosing(RenderProcessHost* render_process_host); |
720 | 718 |
721 // Helper method to delete a RenderFrameProxyHost from the list, if one exists | |
722 // for the given |instance|. | |
723 void DeleteRenderFrameProxyHost(SiteInstance* instance); | |
724 | |
725 // For use in creating RenderFrameHosts. | 719 // For use in creating RenderFrameHosts. |
726 FrameTreeNode* frame_tree_node_; | 720 FrameTreeNode* frame_tree_node_; |
727 | 721 |
728 // Our delegate, not owned by us. Guaranteed non-NULL. | 722 // Our delegate, not owned by us. Guaranteed non-NULL. |
729 Delegate* delegate_; | 723 Delegate* delegate_; |
730 | 724 |
731 // Implemented by the owner of this class. These delegates are installed into | 725 // Implemented by the owner of this class. These delegates are installed into |
732 // all the RenderFrameHosts that we create. | 726 // all the RenderFrameHosts that we create. |
733 RenderFrameHostDelegate* render_frame_delegate_; | 727 RenderFrameHostDelegate* render_frame_delegate_; |
734 RenderViewHostDelegate* render_view_delegate_; | 728 RenderViewHostDelegate* render_view_delegate_; |
(...skipping 26 matching lines...) Expand all Loading... |
761 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_; | 755 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_; |
762 | 756 |
763 // If either of these is non-NULL, the pending navigation is to a chrome: | 757 // If either of these is non-NULL, the pending navigation is to a chrome: |
764 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is | 758 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is |
765 // used for when they reference the same object. If either is non-NULL, the | 759 // used for when they reference the same object. If either is non-NULL, the |
766 // other should be NULL. | 760 // other should be NULL. |
767 // Note: These are not used in PlzNavigate. | 761 // Note: These are not used in PlzNavigate. |
768 scoped_ptr<WebUIImpl> pending_web_ui_; | 762 scoped_ptr<WebUIImpl> pending_web_ui_; |
769 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; | 763 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; |
770 | 764 |
771 // A map of site instance ID to RenderFrameProxyHosts. | 765 class RenderFrameProxyHostMap; |
772 typedef base::hash_map<int32, RenderFrameProxyHost*> RenderFrameProxyHostMap; | 766 scoped_ptr<RenderFrameProxyHostMap> proxy_hosts_; |
773 RenderFrameProxyHostMap proxy_hosts_; | |
774 | 767 |
775 // A list of RenderFrameHosts waiting to shut down after swapping out. We use | 768 // A list of RenderFrameHosts waiting to shut down after swapping out. We use |
776 // a linked list since we expect frequent deletes and no indexed access, and | 769 // a linked list since we expect frequent deletes and no indexed access, and |
777 // because sets don't appear to support linked_ptrs. | 770 // because sets don't appear to support linked_ptrs. |
778 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList; | 771 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList; |
779 RFHPendingDeleteList pending_delete_hosts_; | 772 RFHPendingDeleteList pending_delete_hosts_; |
780 | 773 |
781 // The intersitial page currently shown if any, not own by this class | 774 // The intersitial page currently shown if any, not own by this class |
782 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 775 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
783 InterstitialPageImpl* interstitial_page_; | 776 InterstitialPageImpl* interstitial_page_; |
784 | 777 |
785 NotificationRegistrar registrar_; | |
786 | |
787 // PlzNavigate | 778 // PlzNavigate |
788 // These members store a speculative RenderFrameHost and WebUI. They are | 779 // These members store a speculative RenderFrameHost and WebUI. They are |
789 // created early in a navigation so a renderer process can be started in | 780 // created early in a navigation so a renderer process can be started in |
790 // parallel, if needed. This is purely a performance optimization and is not | 781 // parallel, if needed. This is purely a performance optimization and is not |
791 // required for correct behavior. The created RenderFrameHost might be | 782 // required for correct behavior. The created RenderFrameHost might be |
792 // discarded later on if the final URL's SiteInstance isn't compatible with | 783 // discarded later on if the final URL's SiteInstance isn't compatible with |
793 // what was used to create it. | 784 // what was used to create it. |
794 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not | 785 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not |
795 // the pending ones. | 786 // the pending ones. |
796 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_; | 787 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_; |
797 scoped_ptr<WebUIImpl> speculative_web_ui_; | 788 scoped_ptr<WebUIImpl> speculative_web_ui_; |
798 | 789 |
799 // PlzNavigate | 790 // PlzNavigate |
800 // If true at navigation commit time the current WebUI will be kept instead of | 791 // If true at navigation commit time the current WebUI will be kept instead of |
801 // creating a new one. | 792 // creating a new one. |
802 bool should_reuse_web_ui_; | 793 bool should_reuse_web_ui_; |
803 | 794 |
804 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; | 795 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; |
805 | 796 |
806 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); | 797 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); |
807 }; | 798 }; |
808 | 799 |
809 } // namespace content | 800 } // namespace content |
810 | 801 |
811 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 802 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
OLD | NEW |