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; |
29 class FrameTreeNode; | 30 class FrameTreeNode; |
30 class InterstitialPageImpl; | 31 class InterstitialPageImpl; |
31 class NavigationControllerImpl; | 32 class NavigationControllerImpl; |
32 class NavigationEntry; | 33 class NavigationEntry; |
33 class NavigationEntryImpl; | 34 class NavigationEntryImpl; |
| 35 class NavigatorTestWithBrowserSideNavigation; |
34 class RenderFrameHost; | 36 class RenderFrameHost; |
35 class RenderFrameHostDelegate; | 37 class RenderFrameHostDelegate; |
36 class RenderFrameHostImpl; | 38 class RenderFrameHostImpl; |
37 class RenderFrameHostManagerTest; | 39 class RenderFrameHostManagerTest; |
38 class RenderFrameProxyHost; | 40 class RenderFrameProxyHost; |
39 class RenderViewHost; | 41 class RenderViewHost; |
40 class RenderViewHostImpl; | 42 class RenderViewHostImpl; |
41 class RenderWidgetHostDelegate; | 43 class RenderWidgetHostDelegate; |
42 class RenderWidgetHostView; | 44 class RenderWidgetHostView; |
43 class TestWebContents; | 45 class TestWebContents; |
44 class WebUIImpl; | 46 class WebUIImpl; |
| 47 struct CommonNavigationParams; |
45 | 48 |
46 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a | 49 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a |
47 // current_frame_host() which is the content currently visible to the user. When | 50 // current_frame_host() which is the content currently visible to the user. When |
48 // a frame is told to navigate to a different web site (as determined by | 51 // a frame is told to navigate to a different web site (as determined by |
49 // SiteInstance), it will replace its current RenderFrameHost with a new | 52 // SiteInstance), it will replace its current RenderFrameHost with a new |
50 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process. | 53 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process. |
51 // | 54 // |
52 // Cross-process navigation works like this: | 55 // Cross-process navigation works like this: |
53 // | 56 // |
54 // - RFHM::Navigate determines whether the destination is cross-site, and if so, | 57 // - RFHM::Navigate determines whether the destination is cross-site, and if so, |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 RenderFrameHostImpl* pending_render_frame_host); | 285 RenderFrameHostImpl* pending_render_frame_host); |
283 | 286 |
284 // Resume navigation paused after receiving response headers. | 287 // Resume navigation paused after receiving response headers. |
285 void ResumeResponseDeferredAtStart(); | 288 void ResumeResponseDeferredAtStart(); |
286 | 289 |
287 // Clear navigation transition data. | 290 // Clear navigation transition data. |
288 void ClearNavigationTransitionData(); | 291 void ClearNavigationTransitionData(); |
289 | 292 |
290 // Called when a renderer's frame navigates. | 293 // Called when a renderer's frame navigates. |
291 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host, | 294 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host, |
292 bool was_caused_by_user_gesture); | 295 bool was_caused_by_user_gesture, |
| 296 bool was_within_same_page); |
293 | 297 |
294 // Called when a renderer sets its opener to null. | 298 // Called when a renderer sets its opener to null. |
295 void DidDisownOpener(RenderFrameHost* render_frame_host); | 299 void DidDisownOpener(RenderFrameHost* render_frame_host); |
296 | 300 |
297 // Sets the pending Web UI for the pending navigation, ensuring that the | 301 // Sets the pending Web UI for the pending navigation, ensuring that the |
298 // bindings are appropriate compared to |bindings|. | 302 // bindings are appropriate compared to |bindings|. |
299 void SetPendingWebUI(const GURL& url, int bindings); | 303 void SetPendingWebUI(const GURL& url, int bindings); |
300 | 304 |
301 // Creates and initializes a RenderFrameHost. The |web_ui| is an optional | 305 // Creates and initializes a RenderFrameHost. The |web_ui| is an optional |
302 // input parameter used to double check bindings when swapping back in a | 306 // input parameter used to double check bindings when swapping back in a |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 364 |
361 // Deletes any proxy hosts associated with this node. Used during destruction | 365 // Deletes any proxy hosts associated with this node. Used during destruction |
362 // of WebContentsImpl. | 366 // of WebContentsImpl. |
363 void ResetProxyHosts(); | 367 void ResetProxyHosts(); |
364 | 368 |
365 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy | 369 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy |
366 // that has the given SiteInstance and is associated with this | 370 // that has the given SiteInstance and is associated with this |
367 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. | 371 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. |
368 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); | 372 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); |
369 | 373 |
370 // PlzNavigate: Called when a navigation is ready to commit, to select the | 374 // PlzNavigate |
371 // renderer that will commit it. | 375 // Notifies the RFHM that a navigation has begun so that it can speculatively |
| 376 // create a new renderer process if needed. |
| 377 void BeginNavigation(const FrameHostMsg_BeginNavigation_Params& params, |
| 378 const CommonNavigationParams& common_params); |
| 379 |
| 380 // PlzNavigate |
| 381 // Called when a navigation is ready to commit to select the RenderFrameHost |
| 382 // in which the navigation will commit. |
372 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url, | 383 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url, |
373 ui::PageTransition transition); | 384 ui::PageTransition transition); |
374 | 385 |
| 386 // PlzNavigate |
| 387 // Cancels any state for any ongoing navigation. |
| 388 void CleanUpNavigation(); |
| 389 |
| 390 // PlzNavigate |
| 391 // Clears the speculative members, returning the RenderFrameHost to the caller |
| 392 // for disposal. |
| 393 scoped_ptr<RenderFrameHostImpl> UnsetSpeculativeRenderFrameHost(); |
| 394 |
375 // Notification methods to tell this RenderFrameHostManager that the frame it | 395 // Notification methods to tell this RenderFrameHostManager that the frame it |
376 // is responsible for has started or stopped loading a document. | 396 // is responsible for has started or stopped loading a document. |
377 void OnDidStartLoading(); | 397 void OnDidStartLoading(); |
378 void OnDidStopLoading(); | 398 void OnDidStopLoading(); |
379 | 399 |
380 private: | 400 private: |
| 401 friend class NavigatorTestWithBrowserSideNavigation; |
381 friend class RenderFrameHostManagerTest; | 402 friend class RenderFrameHostManagerTest; |
382 friend class TestWebContents; | 403 friend class TestWebContents; |
383 | 404 |
384 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, | 405 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, |
385 CreateCrossProcessSubframeProxies); | 406 CreateCrossProcessSubframeProxies); |
386 | 407 |
387 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a | 408 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a |
388 // FrameTreeNode's RenderFrameHostManager. | 409 // FrameTreeNode's RenderFrameHostManager. |
389 static bool ClearProxiesInSiteInstance(int32 site_instance_id, | 410 static bool ClearProxiesInSiteInstance(int32 site_instance_id, |
390 FrameTreeNode* node); | 411 FrameTreeNode* node); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 // route ID to be used for the new RenderView to be created. | 492 // route ID to be used for the new RenderView to be created. |
472 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance, | 493 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance, |
473 SiteInstance* new_instance); | 494 SiteInstance* new_instance); |
474 | 495 |
475 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. | 496 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. |
476 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, | 497 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, |
477 int view_routing_id, | 498 int view_routing_id, |
478 int frame_routing_id, | 499 int frame_routing_id, |
479 int flags); | 500 int flags); |
480 | 501 |
| 502 // PlzNavigate |
| 503 // Creates and initializes a speculative RenderFrameHost and/or WebUI for an |
| 504 // ongoing navigation. They might be destroyed and re-created later if the |
| 505 // navigation is redirected to a different site. |
| 506 bool CreateSpeculativeRenderFrameHost(const GURL& url, |
| 507 SiteInstance* old_instance, |
| 508 SiteInstance* new_instance, |
| 509 int bindings); |
| 510 |
481 // Sets up the necessary state for a new RenderViewHost with the given opener, | 511 // Sets up the necessary state for a new RenderViewHost with the given opener, |
482 // if necessary. It creates a RenderFrameProxy in the target renderer process | 512 // if necessary. It creates a RenderFrameProxy in the target renderer process |
483 // with the given |proxy_routing_id|, which is used to route IPC messages when | 513 // with the given |proxy_routing_id|, which is used to route IPC messages when |
484 // in swapped out state. Returns early if the RenderViewHost has already been | 514 // in swapped out state. Returns early if the RenderViewHost has already been |
485 // initialized for another RenderFrameHost. | 515 // initialized for another RenderFrameHost. |
486 // TODO(creis): opener_route_id is currently for the RenderViewHost but should | 516 // TODO(creis): opener_route_id is currently for the RenderViewHost but should |
487 // be for the RenderFrame, since frames can have openers. | 517 // be for the RenderFrame, since frames can have openers. |
488 bool InitRenderView(RenderViewHostImpl* render_view_host, | 518 bool InitRenderView(RenderViewHostImpl* render_view_host, |
489 int opener_route_id, | 519 int opener_route_id, |
490 int proxy_routing_id, | 520 int proxy_routing_id, |
491 bool for_main_frame_navigation); | 521 bool for_main_frame_navigation); |
492 | 522 |
493 // Initialization for RenderFrameHost uses the same sequence as InitRenderView | 523 // Initialization for RenderFrameHost uses the same sequence as InitRenderView |
494 // above. | 524 // above. |
495 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host); | 525 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host); |
496 | 526 |
497 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this | 527 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this |
498 // doesn't require the pending render_frame_host_ pointer to be non-NULL, | 528 // doesn't require the pending render_frame_host_ pointer to be non-NULL, |
499 // since there could be Web UI switching as well. Call this for every commit. | 529 // since there could be Web UI switching as well. Call this for every commit. |
| 530 // If PlzNavigate is enabled the method will set the speculative (not pending) |
| 531 // RenderFrameHost to be the active one. |
500 void CommitPending(); | 532 void CommitPending(); |
501 | 533 |
502 // Runs the unload handler in the old RenderFrameHost, after the new | 534 // Runs the unload handler in the old RenderFrameHost, after the new |
503 // RenderFrameHost has committed. |old_render_frame_host| will either be | 535 // RenderFrameHost has committed. |old_render_frame_host| will either be |
504 // deleted or put on the pending delete list during this call. | 536 // deleted or put on the pending delete list during this call. |
505 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host); | 537 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host); |
506 | 538 |
507 // Discards a RenderFrameHost that was never made active (for active ones | 539 // Discards a RenderFrameHost that was never made active (for active ones |
508 // SwapOutOldFrame is used instead). | 540 // SwapOutOldFrame is used instead). |
509 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host); | 541 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 // A RenderFrameHost used to load a cross-site page. This remains hidden | 608 // A RenderFrameHost used to load a cross-site page. This remains hidden |
577 // while a cross-site request is pending until it calls DidNavigate. It may | 609 // while a cross-site request is pending until it calls DidNavigate. It may |
578 // have an associated Web UI, in which case the Web UI pointer will be non- | 610 // have an associated Web UI, in which case the Web UI pointer will be non- |
579 // NULL. | 611 // NULL. |
580 // | 612 // |
581 // The |pending_web_ui_| may be non-NULL even when the | 613 // The |pending_web_ui_| may be non-NULL even when the |
582 // |pending_render_frame_host_| is NULL. This will happen when we're | 614 // |pending_render_frame_host_| is NULL. This will happen when we're |
583 // transitioning between two Web UI pages: the RFH won't be swapped, so the | 615 // transitioning between two Web UI pages: the RFH won't be swapped, so the |
584 // pending pointer will be unused, but there will be a pending Web UI | 616 // pending pointer will be unused, but there will be a pending Web UI |
585 // associated with the navigation. | 617 // associated with the navigation. |
| 618 // Note: This is not used in PlzNavigate. |
586 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_; | 619 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_; |
587 | 620 |
588 // If a pending request needs to be transferred to another process, this | 621 // If a pending request needs to be transferred to another process, this |
589 // owns the request until it's transferred to the new process, so it will be | 622 // owns the request until it's transferred to the new process, so it will be |
590 // cleaned up if the navigation is cancelled. Otherwise, this is NULL. | 623 // cleaned up if the navigation is cancelled. Otherwise, this is NULL. |
591 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_; | 624 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_; |
592 | 625 |
593 // Tracks information about any navigation paused after receiving response | 626 // Tracks information about any navigation paused after receiving response |
594 // headers. | 627 // headers. |
595 scoped_ptr<GlobalRequestID> response_started_id_; | 628 scoped_ptr<GlobalRequestID> response_started_id_; |
596 | 629 |
597 // If either of these is non-NULL, the pending navigation is to a chrome: | 630 // If either of these is non-NULL, the pending navigation is to a chrome: |
598 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is | 631 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is |
599 // used for when they reference the same object. If either is non-NULL, the | 632 // used for when they reference the same object. If either is non-NULL, the |
600 // other should be NULL. | 633 // other should be NULL. |
| 634 // Note: These are not used in PlzNavigate. |
601 scoped_ptr<WebUIImpl> pending_web_ui_; | 635 scoped_ptr<WebUIImpl> pending_web_ui_; |
602 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; | 636 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; |
603 | 637 |
604 // A map of site instance ID to RenderFrameProxyHosts. | 638 // A map of site instance ID to RenderFrameProxyHosts. |
605 typedef base::hash_map<int32, RenderFrameProxyHost*> RenderFrameProxyHostMap; | 639 typedef base::hash_map<int32, RenderFrameProxyHost*> RenderFrameProxyHostMap; |
606 RenderFrameProxyHostMap proxy_hosts_; | 640 RenderFrameProxyHostMap proxy_hosts_; |
607 | 641 |
608 // A list of RenderFrameHosts waiting to shut down after swapping out. We use | 642 // A list of RenderFrameHosts waiting to shut down after swapping out. We use |
609 // a linked list since we expect frequent deletes and no indexed access, and | 643 // a linked list since we expect frequent deletes and no indexed access, and |
610 // because sets don't appear to support linked_ptrs. | 644 // because sets don't appear to support linked_ptrs. |
611 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList; | 645 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList; |
612 RFHPendingDeleteList pending_delete_hosts_; | 646 RFHPendingDeleteList pending_delete_hosts_; |
613 | 647 |
614 // The intersitial page currently shown if any, not own by this class | 648 // The intersitial page currently shown if any, not own by this class |
615 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 649 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
616 InterstitialPageImpl* interstitial_page_; | 650 InterstitialPageImpl* interstitial_page_; |
617 | 651 |
618 NotificationRegistrar registrar_; | 652 NotificationRegistrar registrar_; |
619 | 653 |
| 654 // PlzNavigate |
| 655 // These members store a speculative RenderFrameHost and WebUI. They are |
| 656 // created early in during a navigation so the renderer process can be started |
| 657 // in parallel with it. This is purely an optimization and is not required for |
| 658 // correct behavior. The created instance might be discarded later on if the |
| 659 // final URL's SiteInstance isn't compatible with what was used to create it. |
| 660 // Note: PlzNavigate only uses speculative RenderFrameHosts and not pending |
| 661 // ones. |
| 662 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_; |
| 663 scoped_ptr<WebUIImpl> speculative_web_ui_; |
| 664 |
| 665 // PlzNavigate |
| 666 // If true at navigation commit time the current WebUI will be kept instead of |
| 667 // creating a new one. |
| 668 bool should_reuse_web_ui_; |
| 669 |
620 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; | 670 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; |
621 | 671 |
622 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); | 672 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); |
623 }; | 673 }; |
624 | 674 |
625 } // namespace content | 675 } // namespace content |
626 | 676 |
627 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 677 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
OLD | NEW |