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; | |
clamy
2014/12/30 16:57:46
Remove this forward declaration (see below).
carlosk
2014/12/31 13:39:19
Done.
| |
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 |
372 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url, | 376 // create a new renderer process if needed. |
373 ui::PageTransition transition); | 377 void BeginNavigation(const FrameHostMsg_BeginNavigation_Params& params, |
clamy
2014/12/30 16:57:46
This method should not take a FrameHostMsg_BeginNa
carlosk
2014/12/31 13:39:19
Done.
| |
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. | |
clamy
2014/12/30 16:57:46
nit: This method is also called by BeginNavigation
carlosk
2014/12/31 13:39:19
Updated the comment.
| |
383 RenderFrameHostImpl* SelectFrameHostForNavigation( | |
carlosk
2014/12/30 15:54:50
I renamed GetFrameHostForNavigation to SelectFrame
clamy
2014/12/30 16:57:46
Acknowledged.
| |
384 const GURL& url, | |
385 ui::PageTransition transition); | |
386 | |
387 // PlzNavigate | |
388 // Cancels any state for any ongoing navigation. | |
389 void CleanUpNavigation(); | |
390 | |
391 // PlzNavigate | |
392 // Clears the speculative members, returning the RenderFrameHost to the caller | |
393 // for disposal. | |
394 scoped_ptr<RenderFrameHostImpl> UnsetSpeculativeRenderFrameHost(); | |
374 | 395 |
375 // Notification methods to tell this RenderFrameHostManager that the frame it | 396 // Notification methods to tell this RenderFrameHostManager that the frame it |
376 // is responsible for has started or stopped loading a document. | 397 // is responsible for has started or stopped loading a document. |
377 void OnDidStartLoading(); | 398 void OnDidStartLoading(); |
378 void OnDidStopLoading(); | 399 void OnDidStopLoading(); |
379 | 400 |
380 private: | 401 private: |
402 friend class NavigatorTestWithBrowserSideNavigation; | |
381 friend class RenderFrameHostManagerTest; | 403 friend class RenderFrameHostManagerTest; |
382 friend class TestWebContents; | 404 friend class TestWebContents; |
383 | 405 |
384 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, | 406 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, |
385 CreateCrossProcessSubframeProxies); | 407 CreateCrossProcessSubframeProxies); |
386 | 408 |
387 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a | 409 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a |
388 // FrameTreeNode's RenderFrameHostManager. | 410 // FrameTreeNode's RenderFrameHostManager. |
389 static bool ClearProxiesInSiteInstance(int32 site_instance_id, | 411 static bool ClearProxiesInSiteInstance(int32 site_instance_id, |
390 FrameTreeNode* node); | 412 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. | 493 // route ID to be used for the new RenderView to be created. |
472 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance, | 494 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance, |
473 SiteInstance* new_instance); | 495 SiteInstance* new_instance); |
474 | 496 |
475 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. | 497 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. |
476 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, | 498 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, |
477 int view_routing_id, | 499 int view_routing_id, |
478 int frame_routing_id, | 500 int frame_routing_id, |
479 int flags); | 501 int flags); |
480 | 502 |
503 // PlzNavigate | |
504 // Creates and initializes a speculative RenderFrameHost and/or WebUI for an | |
505 // ongoing navigation. They might be destroyed and re-created later if the | |
506 // navigation is redirected to a different site. | |
507 bool CreateSpeculativeRenderFrameHost(const GURL& url, | |
508 SiteInstance* old_instance, | |
509 SiteInstance* new_instance, | |
510 int bindings); | |
511 | |
481 // Sets up the necessary state for a new RenderViewHost with the given opener, | 512 // 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 | 513 // 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 | 514 // 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 | 515 // in swapped out state. Returns early if the RenderViewHost has already been |
485 // initialized for another RenderFrameHost. | 516 // initialized for another RenderFrameHost. |
486 // TODO(creis): opener_route_id is currently for the RenderViewHost but should | 517 // TODO(creis): opener_route_id is currently for the RenderViewHost but should |
487 // be for the RenderFrame, since frames can have openers. | 518 // be for the RenderFrame, since frames can have openers. |
488 bool InitRenderView(RenderViewHostImpl* render_view_host, | 519 bool InitRenderView(RenderViewHostImpl* render_view_host, |
489 int opener_route_id, | 520 int opener_route_id, |
490 int proxy_routing_id, | 521 int proxy_routing_id, |
491 bool for_main_frame_navigation); | 522 bool for_main_frame_navigation); |
492 | 523 |
493 // Initialization for RenderFrameHost uses the same sequence as InitRenderView | 524 // Initialization for RenderFrameHost uses the same sequence as InitRenderView |
494 // above. | 525 // above. |
495 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host); | 526 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host); |
496 | 527 |
497 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this | 528 // 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, | 529 // 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. | 530 // since there could be Web UI switching as well. Call this for every commit. |
531 // If PlzNavigate is enabled the method will set the speculative (not pending) | |
532 // RenderFrameHost to be the active one. | |
500 void CommitPending(); | 533 void CommitPending(); |
501 | 534 |
502 // Runs the unload handler in the old RenderFrameHost, after the new | 535 // Runs the unload handler in the old RenderFrameHost, after the new |
503 // RenderFrameHost has committed. |old_render_frame_host| will either be | 536 // RenderFrameHost has committed. |old_render_frame_host| will either be |
504 // deleted or put on the pending delete list during this call. | 537 // deleted or put on the pending delete list during this call. |
505 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host); | 538 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host); |
506 | 539 |
507 // Discards a RenderFrameHost that was never made active (for active ones | 540 // Discards a RenderFrameHost that was never made active (for active ones |
508 // SwapOutOldFrame is used instead). | 541 // SwapOutOldFrame is used instead). |
509 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host); | 542 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 | 609 // 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 | 610 // 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- | 611 // have an associated Web UI, in which case the Web UI pointer will be non- |
579 // NULL. | 612 // NULL. |
580 // | 613 // |
581 // The |pending_web_ui_| may be non-NULL even when the | 614 // The |pending_web_ui_| may be non-NULL even when the |
582 // |pending_render_frame_host_| is NULL. This will happen when we're | 615 // |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 | 616 // 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 | 617 // pending pointer will be unused, but there will be a pending Web UI |
585 // associated with the navigation. | 618 // associated with the navigation. |
619 // Note: This is not used in PlzNavigate. | |
586 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_; | 620 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_; |
587 | 621 |
588 // If a pending request needs to be transferred to another process, this | 622 // 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 | 623 // 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. | 624 // cleaned up if the navigation is cancelled. Otherwise, this is NULL. |
591 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_; | 625 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_; |
592 | 626 |
593 // Tracks information about any navigation paused after receiving response | 627 // Tracks information about any navigation paused after receiving response |
594 // headers. | 628 // headers. |
595 scoped_ptr<GlobalRequestID> response_started_id_; | 629 scoped_ptr<GlobalRequestID> response_started_id_; |
596 | 630 |
597 // If either of these is non-NULL, the pending navigation is to a chrome: | 631 // 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 | 632 // 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 | 633 // used for when they reference the same object. If either is non-NULL, the |
600 // other should be NULL. | 634 // other should be NULL. |
635 // Note: These are not used in PlzNavigate. | |
601 scoped_ptr<WebUIImpl> pending_web_ui_; | 636 scoped_ptr<WebUIImpl> pending_web_ui_; |
602 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; | 637 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; |
603 | 638 |
604 // A map of site instance ID to RenderFrameProxyHosts. | 639 // A map of site instance ID to RenderFrameProxyHosts. |
605 typedef base::hash_map<int32, RenderFrameProxyHost*> RenderFrameProxyHostMap; | 640 typedef base::hash_map<int32, RenderFrameProxyHost*> RenderFrameProxyHostMap; |
606 RenderFrameProxyHostMap proxy_hosts_; | 641 RenderFrameProxyHostMap proxy_hosts_; |
607 | 642 |
608 // A list of RenderFrameHosts waiting to shut down after swapping out. We use | 643 // 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 | 644 // a linked list since we expect frequent deletes and no indexed access, and |
610 // because sets don't appear to support linked_ptrs. | 645 // because sets don't appear to support linked_ptrs. |
611 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList; | 646 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList; |
612 RFHPendingDeleteList pending_delete_hosts_; | 647 RFHPendingDeleteList pending_delete_hosts_; |
613 | 648 |
614 // The intersitial page currently shown if any, not own by this class | 649 // The intersitial page currently shown if any, not own by this class |
615 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 650 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
616 InterstitialPageImpl* interstitial_page_; | 651 InterstitialPageImpl* interstitial_page_; |
617 | 652 |
618 NotificationRegistrar registrar_; | 653 NotificationRegistrar registrar_; |
619 | 654 |
655 // PlzNavigate | |
656 // These members store a speculative RenderFrameHost and WebUI. They are | |
657 // created early in during a navigation so the renderer process can be started | |
658 // in parallel with it. This is purely an optimization and is not required for | |
clamy
2014/12/30 16:57:46
nit: remove with it. Add a performance optimizatio
carlosk
2014/12/31 13:39:19
Done.
| |
659 // correct behavior. The created instance might be discarded later on if the | |
clamy
2014/12/30 16:57:46
nit: s/instance/RenderFrameHost
carlosk
2014/12/31 13:39:19
Done.
| |
660 // final URL's SiteInstance isn't compatible with what was used to create it. | |
661 // Note: PlzNavigate only uses speculative RenderFrameHosts and not pending | |
662 // ones. | |
663 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_; | |
664 scoped_ptr<WebUIImpl> speculative_web_ui_; | |
665 | |
666 // PlzNavigate | |
667 // If true at navigation commit time the current WebUI will be kept instead of | |
668 // creating a new one. | |
669 bool should_reuse_web_ui_; | |
670 | |
620 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; | 671 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; |
621 | 672 |
622 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); | 673 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); |
623 }; | 674 }; |
624 | 675 |
625 } // namespace content | 676 } // namespace content |
626 | 677 |
627 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 678 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
OLD | NEW |