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 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "content/browser/renderer_host/render_view_host_delegate.h" | 14 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 15 #include "content/browser/site_instance_impl.h" | 15 #include "content/browser/site_instance_impl.h" |
| 16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "content/public/browser/global_request_id.h" | 17 #include "content/public/browser/global_request_id.h" |
| 18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/common/referrer.h" | 20 #include "content/public/common/referrer.h" |
| 21 #include "ui/base/page_transition_types.h" | 21 #include "ui/base/page_transition_types.h" |
| 22 | 22 |
| 23 struct FrameHostMsg_BeginNavigation_Params; | |
| 23 struct FrameMsg_Navigate_Params; | 24 struct FrameMsg_Navigate_Params; |
| 24 | 25 |
| 25 namespace content { | 26 namespace content { |
| 26 class BrowserContext; | 27 class BrowserContext; |
| 27 class CrossProcessFrameConnector; | 28 class CrossProcessFrameConnector; |
| 28 class CrossSiteTransferringRequest; | 29 class CrossSiteTransferringRequest; |
| 30 class FrameTreeNode; | |
| 29 class InterstitialPageImpl; | 31 class InterstitialPageImpl; |
| 30 class FrameTreeNode; | |
| 31 class NavigationControllerImpl; | 32 class NavigationControllerImpl; |
| 32 class NavigationEntry; | 33 class NavigationEntry; |
| 33 class NavigationEntryImpl; | 34 class NavigationEntryImpl; |
| 34 class RenderFrameHost; | 35 class RenderFrameHost; |
| 35 class RenderFrameHostDelegate; | 36 class RenderFrameHostDelegate; |
| 36 class RenderFrameHost; | |
| 37 class RenderFrameHostImpl; | 37 class RenderFrameHostImpl; |
| 38 class RenderFrameHostManagerTest; | 38 class RenderFrameHostManagerTest; |
| 39 class RenderFrameProxyHost; | 39 class RenderFrameProxyHost; |
| 40 class RenderViewHost; | 40 class RenderViewHost; |
| 41 class RenderViewHostImpl; | 41 class RenderViewHostImpl; |
| 42 class RenderWidgetHostDelegate; | 42 class RenderWidgetHostDelegate; |
| 43 class RenderWidgetHostView; | 43 class RenderWidgetHostView; |
| 44 class TestWebContents; | 44 class TestWebContents; |
| 45 class WebUIImpl; | 45 class WebUIImpl; |
| 46 struct CommonNavigationParams; | |
| 46 | 47 |
| 47 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a | 48 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a |
| 48 // current_frame_host() which is the content currently visible to the user. When | 49 // current_frame_host() which is the content currently visible to the user. When |
| 49 // a frame is told to navigate to a different web site (as determined by | 50 // a frame is told to navigate to a different web site (as determined by |
| 50 // SiteInstance), it will replace its current RenderFrameHost with a new | 51 // SiteInstance), it will replace its current RenderFrameHost with a new |
| 51 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process. | 52 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process. |
| 52 // | 53 // |
| 53 // Cross-process navigation works like this: | 54 // Cross-process navigation works like this: |
| 54 // | 55 // |
| 55 // - RFHM::Navigate determines whether the destination is cross-site, and if so, | 56 // - RFHM::Navigate determines whether the destination is cross-site, and if so, |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 | 291 |
| 291 // Clear navigation transition data. | 292 // Clear navigation transition data. |
| 292 void ClearNavigationTransitionData(); | 293 void ClearNavigationTransitionData(); |
| 293 | 294 |
| 294 // Called when a renderer's frame navigates. | 295 // Called when a renderer's frame navigates. |
| 295 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host); | 296 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host); |
| 296 | 297 |
| 297 // Called when a renderer sets its opener to null. | 298 // Called when a renderer sets its opener to null. |
| 298 void DidDisownOpener(RenderFrameHost* render_frame_host); | 299 void DidDisownOpener(RenderFrameHost* render_frame_host); |
| 299 | 300 |
| 300 // Helper method to create and initialize a RenderFrameHost. If |flags| | 301 // Creates and initializes a RenderFrameHost. If |flags| has the |
| 301 // has the CREATE_RF_SWAPPED_OUT bit set from the CreateRenderFrameFlags | 302 // CREATE_RF_SWAPPED_OUT bit set from the CreateRenderFrameFlags enum, it will |
| 302 // enum, it will initially be placed on the swapped out hosts list. | 303 // initially be placed on the swapped out hosts list. If |routing_id_ptr| is |
| 303 // Returns the routing id of the *view* associated with the frame. | 304 // not NULL it will be set to the routing id of the *view* associated with the |
| 304 int CreateRenderFrame(SiteInstance* instance, int opener_route_id, int flags); | 305 // frame. |
| 306 scoped_ptr<RenderFrameHostImpl> CreateRenderFrame(SiteInstance* instance, | |
| 307 int opener_route_id, | |
| 308 int flags, | |
| 309 const WebUIImpl* web_ui, | |
| 310 int* routing_id_ptr); | |
| 305 | 311 |
| 306 // Helper method to create and initialize a RenderFrameProxyHost and return | 312 // Helper method to create and initialize a RenderFrameProxyHost and return |
| 307 // its routing id. | 313 // its routing id. |
| 308 int CreateRenderFrameProxy(SiteInstance* instance); | 314 int CreateRenderFrameProxy(SiteInstance* instance); |
| 309 | 315 |
| 310 // Sets the passed passed interstitial as the currently showing interstitial. | 316 // Sets the passed passed interstitial as the currently showing interstitial. |
| 311 // |interstitial_page| should be non NULL (use the remove_interstitial_page | 317 // |interstitial_page| should be non NULL (use the remove_interstitial_page |
| 312 // method to unset the interstitial) and no interstitial page should be set | 318 // method to unset the interstitial) and no interstitial page should be set |
| 313 // when there is already a non NULL interstitial page set. | 319 // when there is already a non NULL interstitial page set. |
| 314 void set_interstitial_page(InterstitialPageImpl* interstitial_page) { | 320 void set_interstitial_page(InterstitialPageImpl* interstitial_page) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 | 358 |
| 353 // Deletes any proxy hosts associated with this node. Used during destruction | 359 // Deletes any proxy hosts associated with this node. Used during destruction |
| 354 // of WebContentsImpl. | 360 // of WebContentsImpl. |
| 355 void ResetProxyHosts(); | 361 void ResetProxyHosts(); |
| 356 | 362 |
| 357 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy | 363 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy |
| 358 // that has the given SiteInstance and is associated with this | 364 // that has the given SiteInstance and is associated with this |
| 359 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. | 365 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. |
| 360 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); | 366 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); |
| 361 | 367 |
| 362 // PlzNavigate: Called when a navigation is ready to commit, to select the | 368 // PlzNavigate |
| 363 // renderer that will commit it. | 369 // Notifies the RFHM that a navigation is about to begin so that it can |
| 370 // speculatively spawn a new renderer process if needed. | |
| 371 void BeginNavigation(const FrameHostMsg_BeginNavigation_Params& params, | |
| 372 const CommonNavigationParams& common_params); | |
| 373 | |
| 374 // PlzNavigate | |
| 375 // Called when a navigation is ready to commit, to select the renderer that | |
| 376 // will commit it. | |
| 364 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url, | 377 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url, |
| 365 ui::PageTransition transition); | 378 ui::PageTransition transition); |
| 366 | 379 |
| 380 // PlzNavigate | |
| 381 // Cancels any ongoing navigation. | |
| 382 void CleanUpNavigation(); | |
| 383 | |
| 384 // PlzNavigate | |
| 385 // Returns the speculative RenderFrameHost, or NULL if there is no pending | |
|
nasko
2014/11/25 00:19:11
nit: null
carlosk
2014/11/28 13:08:17
Done.
| |
| 386 // one. | |
| 387 RenderFrameHostImpl* speculative_render_frame_host() const { | |
|
nasko
2014/11/25 00:19:11
This isn't needed to be public. The tests that use
carlosk
2014/11/28 13:08:17
Done.
| |
| 388 return speculative_render_frame_host_.get(); | |
| 389 } | |
| 390 | |
| 367 private: | 391 private: |
| 368 friend class RenderFrameHostManagerTest; | 392 friend class RenderFrameHostManagerTest; |
| 369 friend class TestWebContents; | 393 friend class TestWebContents; |
| 370 | 394 |
| 371 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, | 395 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, |
| 372 CreateCrossProcessSubframeProxies); | 396 CreateCrossProcessSubframeProxies); |
| 373 | 397 |
| 374 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a | 398 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a |
| 375 // FrameTreeNode's RenderFrameHostManager. | 399 // FrameTreeNode's RenderFrameHostManager. |
| 376 static bool ClearProxiesInSiteInstance(int32 site_instance_id, | 400 static bool ClearProxiesInSiteInstance(int32 site_instance_id, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 394 // SiteInstance's site and when we later call IsSameWebSite. If there is no | 418 // SiteInstance's site and when we later call IsSameWebSite. If there is no |
| 395 // current NavigationEntry, check the current SiteInstance's site, which might | 419 // current NavigationEntry, check the current SiteInstance's site, which might |
| 396 // already be committed to a Web UI URL (such as the NTP). | 420 // already be committed to a Web UI URL (such as the NTP). |
| 397 bool ShouldSwapBrowsingInstancesForNavigation( | 421 bool ShouldSwapBrowsingInstancesForNavigation( |
| 398 const GURL& current_effective_url, | 422 const GURL& current_effective_url, |
| 399 bool current_is_view_source_mode, | 423 bool current_is_view_source_mode, |
| 400 SiteInstance* new_site_instance, | 424 SiteInstance* new_site_instance, |
| 401 const GURL& new_effective_url, | 425 const GURL& new_effective_url, |
| 402 bool new_is_view_source_mode) const; | 426 bool new_is_view_source_mode) const; |
| 403 | 427 |
| 428 // Creates a new Web UI, ensuring that the bindings are appropriate compared | |
| 429 // to |bindings|. The caller is responsible for the instance ownership. | |
| 430 WebUIImpl* CreateWebUI(const GURL& url, int bindings); | |
| 431 | |
| 404 // Returns true if it is safe to reuse the current WebUI when navigating from | 432 // Returns true if it is safe to reuse the current WebUI when navigating from |
| 405 // |current_entry| to |new_url|. | 433 // |current_entry| to |new_url|. |
| 406 bool ShouldReuseWebUI( | 434 bool ShouldReuseWebUI( |
| 407 const NavigationEntry* current_entry, | 435 const NavigationEntry* current_entry, |
| 408 const GURL& new_url) const; | 436 const GURL& new_url) const; |
| 409 | 437 |
| 410 // Returns the SiteInstance to use for the navigation. | 438 // Returns the SiteInstance to use for the navigation. |
| 411 SiteInstance* GetSiteInstanceForNavigation( | 439 SiteInstance* GetSiteInstanceForNavigation( |
| 412 const GURL& dest_url, | 440 const GURL& dest_url, |
| 413 SiteInstance* dest_instance, | 441 SiteInstance* dest_instance, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 435 SiteInstance* current_instance, | 463 SiteInstance* current_instance, |
| 436 NavigationEntry* current_entry); | 464 NavigationEntry* current_entry); |
| 437 | 465 |
| 438 // Creates a new RenderFrameHostImpl for the |new_instance| while respecting | 466 // Creates a new RenderFrameHostImpl for the |new_instance| while respecting |
| 439 // the opener route if needed and stores it in pending_render_frame_host_. | 467 // the opener route if needed and stores it in pending_render_frame_host_. |
| 440 void CreateRenderFrameHostForNewSiteInstance( | 468 void CreateRenderFrameHostForNewSiteInstance( |
| 441 SiteInstance* old_instance, | 469 SiteInstance* old_instance, |
| 442 SiteInstance* new_instance, | 470 SiteInstance* new_instance, |
| 443 bool is_main_frame); | 471 bool is_main_frame); |
| 444 | 472 |
| 473 // Ensure that we have created RFHs for the new RFH's opener chain if | |
| 474 // we are staying in the same BrowsingInstance. This allows the new RFH | |
| 475 // to send cross-process script calls to its opener(s). Returns the opener | |
| 476 // route ID to be used for the new RenderView to be created. | |
| 477 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance, | |
| 478 SiteInstance* new_instance); | |
| 479 | |
| 445 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. | 480 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. |
| 446 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, | 481 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, |
| 447 int view_routing_id, | 482 int view_routing_id, |
| 448 int frame_routing_id, | 483 int frame_routing_id, |
| 449 int flags); | 484 int flags); |
| 450 | 485 |
| 486 // PlzNavigate | |
| 487 // Creates a new RenderFrameHost and does all required supporting work for the | |
| 488 // speculative creation of a new renderer for an ongoing navigation request. | |
| 489 // This RenderFrameHost might be destroyed later if the final navigation | |
| 490 // destination doesn't match the initial one. | |
| 491 bool CreateSpeculativeRenderFrameHost(const GURL& url, | |
| 492 SiteInstance* old_instance, | |
| 493 SiteInstance* new_instance, | |
| 494 int bindings); | |
| 495 | |
| 451 // Sets up the necessary state for a new RenderViewHost with the given opener, | 496 // Sets up the necessary state for a new RenderViewHost with the given opener, |
| 452 // if necessary. It creates a RenderFrameProxy in the target renderer process | 497 // if necessary. It creates a RenderFrameProxy in the target renderer process |
| 453 // with the given |proxy_routing_id|, which is used to route IPC messages when | 498 // with the given |proxy_routing_id|, which is used to route IPC messages when |
| 454 // in swapped out state. Returns early if the RenderViewHost has already been | 499 // in swapped out state. Returns early if the RenderViewHost has already been |
| 455 // initialized for another RenderFrameHost. | 500 // initialized for another RenderFrameHost. |
| 456 // TODO(creis): opener_route_id is currently for the RenderViewHost but should | 501 // TODO(creis): opener_route_id is currently for the RenderViewHost but should |
| 457 // be for the RenderFrame, since frames can have openers. | 502 // be for the RenderFrame, since frames can have openers. |
| 458 bool InitRenderView(RenderViewHostImpl* render_view_host, | 503 bool InitRenderView(RenderViewHostImpl* render_view_host, |
| 459 int opener_route_id, | 504 int opener_route_id, |
| 460 int proxy_routing_id, | 505 int proxy_routing_id, |
| 461 bool for_main_frame_navigation); | 506 bool for_main_frame_navigation); |
| 462 | 507 |
| 463 // Initialization for RenderFrameHost uses the same sequence as InitRenderView | 508 // Initialization for RenderFrameHost uses the same sequence as InitRenderView |
| 464 // above. | 509 // above. |
| 465 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host); | 510 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host); |
| 466 | 511 |
| 467 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this | 512 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this |
| 468 // doesn't require the pending render_frame_host_ pointer to be non-NULL, | 513 // doesn't require the pending render_frame_host_ pointer to be non-NULL, |
| 469 // since there could be Web UI switching as well. Call this for every commit. | 514 // since there could be Web UI switching as well. Call this for every commit. |
| 470 void CommitPending(); | 515 // With PlzNavigate enabled, |use_speculative_rfh| can be set to true which |
| 516 // will cause the speculative RenderFrameHost to be the active one. | |
| 517 void CommitPending(bool use_speculative_rfh); | |
| 471 | 518 |
| 472 // Runs the unload handler in the old RenderFrameHost, after the new | 519 // Runs the unload handler in the old RenderFrameHost, after the new |
| 473 // RenderFrameHost has committed. |old_render_frame_host| will either be | 520 // RenderFrameHost has committed. |old_render_frame_host| will either be |
| 474 // deleted or put on the pending delete list during this call. | 521 // deleted or put on the pending delete list during this call. |
| 475 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host); | 522 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host); |
| 476 | 523 |
| 524 // Discards a RenderFrameHost that was never made active (for active ones | |
| 525 // SwapOutOldFrame is used instead). | |
| 526 void DiscardRenderFrameHost( | |
| 527 scoped_ptr<RenderFrameHostImpl> render_frame_host); | |
| 528 | |
| 477 // Holds |render_frame_host| until it can be deleted when its swap out ACK | 529 // Holds |render_frame_host| until it can be deleted when its swap out ACK |
| 478 // arrives. | 530 // arrives. |
| 479 void MoveToPendingDeleteHosts( | 531 void MoveToPendingDeleteHosts( |
| 480 scoped_ptr<RenderFrameHostImpl> render_frame_host); | 532 scoped_ptr<RenderFrameHostImpl> render_frame_host); |
| 481 | 533 |
| 482 // Shutdown all RenderFrameProxyHosts in a SiteInstance. This is called to | 534 // Shutdown all RenderFrameProxyHosts in a SiteInstance. This is called to |
| 483 // shutdown frames when all the frames in a SiteInstance are confirmed to be | 535 // shutdown frames when all the frames in a SiteInstance are confirmed to be |
| 484 // swapped out. | 536 // swapped out. |
| 485 void ShutdownRenderFrameProxyHostsInSiteInstance(int32 site_instance_id); | 537 void ShutdownRenderFrameProxyHostsInSiteInstance(int32 site_instance_id); |
| 486 | 538 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 RFHPendingDeleteList pending_delete_hosts_; | 625 RFHPendingDeleteList pending_delete_hosts_; |
| 574 | 626 |
| 575 // The intersitial page currently shown if any, not own by this class | 627 // The intersitial page currently shown if any, not own by this class |
| 576 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 628 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
| 577 InterstitialPageImpl* interstitial_page_; | 629 InterstitialPageImpl* interstitial_page_; |
| 578 | 630 |
| 579 NotificationRegistrar registrar_; | 631 NotificationRegistrar registrar_; |
| 580 | 632 |
| 581 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; | 633 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; |
| 582 | 634 |
| 635 // PlzNavigate | |
| 636 // Members to store the speculative RFH created upon starting a navigation | |
| 637 // allowing the creation of the renderer process as early as possible. | |
| 638 // Might be discarded later on if the final URL's SiteInstance doesn't match | |
| 639 // what was assumed in the beginning. | |
| 640 // Note: speculative RenderFrameHost is only used for PlzNavigate and pending | |
| 641 // only for the regular navigation (not yet true, but will be). | |
|
clamy
2014/11/25 16:50:57
Remove the not yet true mention. It is true by now
carlosk
2014/11/28 13:08:17
Done.
| |
| 642 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_; | |
| 643 scoped_ptr<WebUIImpl> speculative_web_ui_; | |
| 644 | |
| 645 // PlzNavigate | |
| 646 // If true at navigation commit time the current WebUI will be kept instead of | |
| 647 // creating a new one. | |
| 648 bool should_reuse_web_ui_; | |
| 649 | |
| 583 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); | 650 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); |
| 584 }; | 651 }; |
| 585 | 652 |
| 586 } // namespace content | 653 } // namespace content |
| 587 | 654 |
| 588 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 655 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
| OLD | NEW |