Chromium Code Reviews| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 711 ui::PageTransition transition, | 706 ui::PageTransition transition, |
| 712 bool dest_is_restore, | 707 bool dest_is_restore, |
| 713 bool dest_is_view_source_mode, | 708 bool dest_is_view_source_mode, |
| 714 const GlobalRequestID& transferred_request_id, | 709 const GlobalRequestID& transferred_request_id, |
| 715 int bindings); | 710 int bindings); |
| 716 | 711 |
| 717 // Called when a renderer process is starting to close. We should not | 712 // Called when a renderer process is starting to close. We should not |
| 718 // schedule new navigations in its swapped out RenderFrameHosts after this. | 713 // schedule new navigations in its swapped out RenderFrameHosts after this. |
| 719 void RendererProcessClosing(RenderProcessHost* render_process_host); | 714 void RendererProcessClosing(RenderProcessHost* render_process_host); |
| 720 | 715 |
| 721 // Helper method to delete a RenderFrameProxyHost from the list, if one exists | 716 std::map<int, RenderFrameProxyHost*> GetAllProxyHostsForTesting(); |
|
ncarter (slow)
2015/07/21 19:07:15
If you made this public, we wouldn't need "friend
ncarter (slow)
2015/07/21 19:07:15
Not clear what the ints keys are here -- add a com
Avi (use Gerrit)
2015/07/21 20:45:16
Done.
| |
| 722 // for the given |instance|. | |
| 723 void DeleteRenderFrameProxyHost(SiteInstance* instance); | |
| 724 | 717 |
| 725 // For use in creating RenderFrameHosts. | 718 // For use in creating RenderFrameHosts. |
| 726 FrameTreeNode* frame_tree_node_; | 719 FrameTreeNode* frame_tree_node_; |
| 727 | 720 |
| 728 // Our delegate, not owned by us. Guaranteed non-NULL. | 721 // Our delegate, not owned by us. Guaranteed non-NULL. |
| 729 Delegate* delegate_; | 722 Delegate* delegate_; |
| 730 | 723 |
| 731 // Implemented by the owner of this class. These delegates are installed into | 724 // Implemented by the owner of this class. These delegates are installed into |
| 732 // all the RenderFrameHosts that we create. | 725 // all the RenderFrameHosts that we create. |
| 733 RenderFrameHostDelegate* render_frame_delegate_; | 726 RenderFrameHostDelegate* render_frame_delegate_; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 761 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_; | 754 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_; |
| 762 | 755 |
| 763 // If either of these is non-NULL, the pending navigation is to a chrome: | 756 // 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 | 757 // 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 | 758 // used for when they reference the same object. If either is non-NULL, the |
| 766 // other should be NULL. | 759 // other should be NULL. |
| 767 // Note: These are not used in PlzNavigate. | 760 // Note: These are not used in PlzNavigate. |
| 768 scoped_ptr<WebUIImpl> pending_web_ui_; | 761 scoped_ptr<WebUIImpl> pending_web_ui_; |
| 769 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; | 762 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; |
| 770 | 763 |
| 771 // A map of site instance ID to RenderFrameProxyHosts. | 764 class RenderFrameProxyHostMap; |
| 772 typedef base::hash_map<int32, RenderFrameProxyHost*> RenderFrameProxyHostMap; | 765 scoped_ptr<RenderFrameProxyHostMap> proxy_hosts_; |
| 773 RenderFrameProxyHostMap proxy_hosts_; | |
| 774 | 766 |
| 775 // A list of RenderFrameHosts waiting to shut down after swapping out. We use | 767 // 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 | 768 // a linked list since we expect frequent deletes and no indexed access, and |
| 777 // because sets don't appear to support linked_ptrs. | 769 // because sets don't appear to support linked_ptrs. |
| 778 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList; | 770 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList; |
| 779 RFHPendingDeleteList pending_delete_hosts_; | 771 RFHPendingDeleteList pending_delete_hosts_; |
| 780 | 772 |
| 781 // The intersitial page currently shown if any, not own by this class | 773 // The intersitial page currently shown if any, not own by this class |
| 782 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 774 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
| 783 InterstitialPageImpl* interstitial_page_; | 775 InterstitialPageImpl* interstitial_page_; |
| 784 | 776 |
| 785 NotificationRegistrar registrar_; | |
| 786 | |
| 787 // PlzNavigate | 777 // PlzNavigate |
| 788 // These members store a speculative RenderFrameHost and WebUI. They are | 778 // These members store a speculative RenderFrameHost and WebUI. They are |
| 789 // created early in a navigation so a renderer process can be started in | 779 // 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 | 780 // parallel, if needed. This is purely a performance optimization and is not |
| 791 // required for correct behavior. The created RenderFrameHost might be | 781 // required for correct behavior. The created RenderFrameHost might be |
| 792 // discarded later on if the final URL's SiteInstance isn't compatible with | 782 // discarded later on if the final URL's SiteInstance isn't compatible with |
| 793 // what was used to create it. | 783 // what was used to create it. |
| 794 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not | 784 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not |
| 795 // the pending ones. | 785 // the pending ones. |
| 796 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_; | 786 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_; |
| 797 scoped_ptr<WebUIImpl> speculative_web_ui_; | 787 scoped_ptr<WebUIImpl> speculative_web_ui_; |
| 798 | 788 |
| 799 // PlzNavigate | 789 // PlzNavigate |
| 800 // If true at navigation commit time the current WebUI will be kept instead of | 790 // If true at navigation commit time the current WebUI will be kept instead of |
| 801 // creating a new one. | 791 // creating a new one. |
| 802 bool should_reuse_web_ui_; | 792 bool should_reuse_web_ui_; |
| 803 | 793 |
| 804 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; | 794 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; |
| 805 | 795 |
| 806 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); | 796 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); |
| 807 }; | 797 }; |
| 808 | 798 |
| 809 } // namespace content | 799 } // namespace content |
| 810 | 800 |
| 811 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 801 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
| OLD | NEW |