| 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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/browser/renderer_host/render_view_host_delegate.h" | 12 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 13 #include "content/browser/site_instance_impl.h" | 13 #include "content/browser/site_instance_impl.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/public/browser/global_request_id.h" | 15 #include "content/public/browser/global_request_id.h" |
| 16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/common/referrer.h" | 18 #include "content/public/common/referrer.h" |
| 19 #include "ui/base/page_transition_types.h" | 19 #include "ui/base/page_transition_types.h" |
| 20 | 20 |
| 21 struct FrameHostMsg_BeginNavigation_Params; | |
| 22 struct FrameMsg_Navigate_Params; | 21 struct FrameMsg_Navigate_Params; |
| 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 InterstitialPageImpl; | 27 class InterstitialPageImpl; |
| 29 class FrameTreeNode; | 28 class FrameTreeNode; |
| 30 class NavigationControllerImpl; | 29 class NavigationControllerImpl; |
| 31 class NavigationEntry; | 30 class NavigationEntry; |
| 32 class NavigationEntryImpl; | 31 class NavigationEntryImpl; |
| 33 class NavigationRequest; | |
| 34 class RenderFrameHost; | 32 class RenderFrameHost; |
| 35 class RenderFrameHostDelegate; | 33 class RenderFrameHostDelegate; |
| 36 class RenderFrameHost; | 34 class RenderFrameHost; |
| 37 class RenderFrameHostImpl; | 35 class RenderFrameHostImpl; |
| 38 class RenderFrameHostManagerTest; | 36 class RenderFrameHostManagerTest; |
| 39 class RenderFrameProxyHost; | 37 class RenderFrameProxyHost; |
| 40 class RenderViewHost; | 38 class RenderViewHost; |
| 41 class RenderViewHostImpl; | 39 class RenderViewHostImpl; |
| 42 class RenderWidgetHostDelegate; | 40 class RenderWidgetHostDelegate; |
| 43 class RenderWidgetHostView; | 41 class RenderWidgetHostView; |
| 44 class TestWebContents; | 42 class TestWebContents; |
| 45 class WebUIImpl; | 43 class WebUIImpl; |
| 46 struct CommonNavigationParams; | |
| 47 struct NavigationBeforeCommitInfo; | |
| 48 struct RequestNavigationParams; | |
| 49 | 44 |
| 50 // Manages RenderFrameHosts for a FrameTreeNode. This class acts as a state | 45 // Manages RenderFrameHosts for a FrameTreeNode. This class acts as a state |
| 51 // machine to make cross-process navigations in a frame possible. | 46 // machine to make cross-process navigations in a frame possible. |
| 52 class CONTENT_EXPORT RenderFrameHostManager : public NotificationObserver { | 47 class CONTENT_EXPORT RenderFrameHostManager : public NotificationObserver { |
| 53 public: | 48 public: |
| 54 // Functions implemented by our owner that we need. | 49 // Functions implemented by our owner that we need. |
| 55 // | 50 // |
| 56 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl | 51 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl |
| 57 // that are required to run this class. The design should probably be better | 52 // that are required to run this class. The design should probably be better |
| 58 // such that these are more clear. | 53 // such that these are more clear. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // Returns the current committed Web UI or NULL if none applies. | 180 // Returns the current committed Web UI or NULL if none applies. |
| 186 WebUIImpl* web_ui() const { return web_ui_.get(); } | 181 WebUIImpl* web_ui() const { return web_ui_.get(); } |
| 187 | 182 |
| 188 // Returns the Web UI for the pending navigation, or NULL of none applies. | 183 // Returns the Web UI for the pending navigation, or NULL of none applies. |
| 189 WebUIImpl* pending_web_ui() const { | 184 WebUIImpl* pending_web_ui() const { |
| 190 return pending_web_ui_.get() ? pending_web_ui_.get() : | 185 return pending_web_ui_.get() ? pending_web_ui_.get() : |
| 191 pending_and_current_web_ui_.get(); | 186 pending_and_current_web_ui_.get(); |
| 192 } | 187 } |
| 193 | 188 |
| 194 // Sets the pending Web UI for the pending navigation, ensuring that the | 189 // Sets the pending Web UI for the pending navigation, ensuring that the |
| 195 // bindings are appropriate for the given NavigationEntry. | 190 // bindings are appropriate compared to |bindings|. |
| 196 void SetPendingWebUI(const NavigationEntryImpl& entry); | 191 void SetPendingWebUI(const GURL& url, int bindings); |
| 197 | 192 |
| 198 // Called when we want to instruct the renderer to navigate to the given | 193 // Called when we want to instruct the renderer to navigate to the given |
| 199 // navigation entry. It may create a new RenderFrameHost or re-use an existing | 194 // navigation entry. It may create a new RenderFrameHost or re-use an existing |
| 200 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one | 195 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one |
| 201 // could not be created. | 196 // could not be created. |
| 202 RenderFrameHostImpl* Navigate(const NavigationEntryImpl& entry); | 197 RenderFrameHostImpl* Navigate(const NavigationEntryImpl& entry); |
| 203 | 198 |
| 204 // Instructs the various live views to stop. Called when the user directed the | 199 // Instructs the various live views to stop. Called when the user directed the |
| 205 // page to stop loading. | 200 // page to stop loading. |
| 206 void Stop(); | 201 void Stop(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 304 |
| 310 // Deletes any proxy hosts associated with this node. Used during destruction | 305 // Deletes any proxy hosts associated with this node. Used during destruction |
| 311 // of WebContentsImpl. | 306 // of WebContentsImpl. |
| 312 void ResetProxyHosts(); | 307 void ResetProxyHosts(); |
| 313 | 308 |
| 314 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy | 309 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy |
| 315 // that has the given SiteInstance and is associated with this | 310 // that has the given SiteInstance and is associated with this |
| 316 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. | 311 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. |
| 317 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); | 312 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); |
| 318 | 313 |
| 319 // PlzNavigate: sends a RequestNavigation IPC to the renderer to ask it to | 314 // PlzNavigate: Called when a navigation is ready to commit, to select the |
| 320 // navigate. If no live renderer is present, then the navigation request will | 315 // renderer that will commit it. |
| 321 // be sent directly to the ResourceDispatcherHost. Takes ownership of | 316 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url, |
| 322 // |navigation_request|. | 317 ui::PageTransition transition); |
| 323 bool RequestNavigation(scoped_ptr<NavigationRequest> navigation_request, | |
| 324 const RequestNavigationParams& request_params); | |
| 325 | |
| 326 // PlzNavigate: Used to start a navigation. OnBeginNavigation is called | |
| 327 // directly by RequestNavigation when there is no live renderer. Otherwise, it | |
| 328 // is called following a BeginNavigation IPC from the renderer (which in | |
| 329 // browser-initiated navigation also happens after RequestNavigation has been | |
| 330 // called). | |
| 331 void OnBeginNavigation(const FrameHostMsg_BeginNavigation_Params& params, | |
| 332 const CommonNavigationParams& common_params); | |
| 333 | |
| 334 // PlzNavigate: Called when a navigation request has received a response, to | |
| 335 // select a renderer to use for the navigation. | |
| 336 void CommitNavigation(const NavigationBeforeCommitInfo& info); | |
| 337 | 318 |
| 338 private: | 319 private: |
| 339 friend class RenderFrameHostManagerTest; | 320 friend class RenderFrameHostManagerTest; |
| 340 friend class TestWebContents; | 321 friend class TestWebContents; |
| 341 | 322 |
| 342 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, | 323 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, |
| 343 CreateCrossProcessSubframeProxies); | 324 CreateCrossProcessSubframeProxies); |
| 344 | 325 |
| 345 // Returns the current navigation request (used in the PlzNavigate navigation | |
| 346 // logic refactoring project). | |
| 347 NavigationRequest* navigation_request_for_testing() const { | |
| 348 return navigation_request_.get(); } | |
| 349 | |
| 350 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a | 326 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a |
| 351 // FrameTreeNode's RenderFrameHostManager. | 327 // FrameTreeNode's RenderFrameHostManager. |
| 352 static bool ClearProxiesInSiteInstance(int32 site_instance_id, | 328 static bool ClearProxiesInSiteInstance(int32 site_instance_id, |
| 353 FrameTreeNode* node); | 329 FrameTreeNode* node); |
| 354 | 330 |
| 355 // Returns whether this tab should transition to a new renderer for | 331 // Returns whether this tab should transition to a new renderer for |
| 356 // cross-site URLs. Enabled unless we see the --process-per-tab command line | 332 // cross-site URLs. Enabled unless we see the --process-per-tab command line |
| 357 // switch. Can be overridden in unit tests. | 333 // switch. Can be overridden in unit tests. |
| 358 bool ShouldTransitionCrossSite(); | 334 bool ShouldTransitionCrossSite(); |
| 359 | 335 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 371 // current NavigationEntry, check the current SiteInstance's site, which might | 347 // current NavigationEntry, check the current SiteInstance's site, which might |
| 372 // already be committed to a Web UI URL (such as the NTP). | 348 // already be committed to a Web UI URL (such as the NTP). |
| 373 bool ShouldSwapBrowsingInstancesForNavigation( | 349 bool ShouldSwapBrowsingInstancesForNavigation( |
| 374 const GURL& current_effective_url, | 350 const GURL& current_effective_url, |
| 375 bool current_is_view_source_mode, | 351 bool current_is_view_source_mode, |
| 376 SiteInstance* new_site_instance, | 352 SiteInstance* new_site_instance, |
| 377 const GURL& new_effective_url, | 353 const GURL& new_effective_url, |
| 378 bool new_is_view_source_mode) const; | 354 bool new_is_view_source_mode) const; |
| 379 | 355 |
| 380 // Returns true if it is safe to reuse the current WebUI when navigating from | 356 // Returns true if it is safe to reuse the current WebUI when navigating from |
| 381 // |current_entry| to |new_entry|. | 357 // |current_entry| to |new_url|. |
| 382 bool ShouldReuseWebUI( | 358 bool ShouldReuseWebUI( |
| 383 const NavigationEntry* current_entry, | 359 const NavigationEntry* current_entry, |
| 384 const NavigationEntryImpl* new_entry) const; | 360 const GURL& new_url) const; |
| 385 | 361 |
| 386 // Returns the SiteInstance to use for the navigation. | 362 // Returns the SiteInstance to use for the navigation. |
| 387 SiteInstance* GetSiteInstanceForNavigation( | 363 SiteInstance* GetSiteInstanceForNavigation( |
| 388 const GURL& dest_url, | 364 const GURL& dest_url, |
| 389 SiteInstance* dest_instance, | 365 SiteInstance* dest_instance, |
| 390 ui::PageTransition dest_transition, | 366 ui::PageTransition dest_transition, |
| 391 bool dest_is_restore, | 367 bool dest_is_restore, |
| 392 bool dest_is_view_source_mode); | 368 bool dest_is_view_source_mode); |
| 393 | 369 |
| 394 // Returns an appropriate SiteInstance object for the given |dest_url|, | 370 // Returns an appropriate SiteInstance object for the given |dest_url|, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 | 427 |
| 452 // Helper method to terminate the pending RenderViewHost. | 428 // Helper method to terminate the pending RenderViewHost. |
| 453 void CancelPending(); | 429 void CancelPending(); |
| 454 | 430 |
| 455 // Helper method to set the active RenderFrameHost. Returns the old | 431 // Helper method to set the active RenderFrameHost. Returns the old |
| 456 // RenderFrameHost and updates counts. | 432 // RenderFrameHost and updates counts. |
| 457 scoped_ptr<RenderFrameHostImpl> SetRenderFrameHost( | 433 scoped_ptr<RenderFrameHostImpl> SetRenderFrameHost( |
| 458 scoped_ptr<RenderFrameHostImpl> render_frame_host); | 434 scoped_ptr<RenderFrameHostImpl> render_frame_host); |
| 459 | 435 |
| 460 RenderFrameHostImpl* UpdateStateForNavigate( | 436 RenderFrameHostImpl* UpdateStateForNavigate( |
| 461 const NavigationEntryImpl& entry); | 437 const GURL& url, |
| 438 SiteInstance* instance, |
| 439 ui::PageTransition transition, |
| 440 bool is_restore, |
| 441 bool is_view_source_mode, |
| 442 const GlobalRequestID& transferred_request_id, |
| 443 int bindings); |
| 462 | 444 |
| 463 // Called when a renderer process is starting to close. We should not | 445 // Called when a renderer process is starting to close. We should not |
| 464 // schedule new navigations in its swapped out RenderFrameHosts after this. | 446 // schedule new navigations in its swapped out RenderFrameHosts after this. |
| 465 void RendererProcessClosing(RenderProcessHost* render_process_host); | 447 void RendererProcessClosing(RenderProcessHost* render_process_host); |
| 466 | 448 |
| 467 // Helper method to delete a RenderFrameProxyHost from the list, if one exists | 449 // Helper method to delete a RenderFrameProxyHost from the list, if one exists |
| 468 // for the given |instance|. | 450 // for the given |instance|. |
| 469 void DeleteRenderFrameProxyHost(SiteInstance* instance); | 451 void DeleteRenderFrameProxyHost(SiteInstance* instance); |
| 470 | 452 |
| 471 // For use in creating RenderFrameHosts. | 453 // For use in creating RenderFrameHosts. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 typedef base::hash_map<int32, linked_ptr<RenderFrameHostImpl> > | 511 typedef base::hash_map<int32, linked_ptr<RenderFrameHostImpl> > |
| 530 RFHPendingDeleteMap; | 512 RFHPendingDeleteMap; |
| 531 RFHPendingDeleteMap pending_delete_hosts_; | 513 RFHPendingDeleteMap pending_delete_hosts_; |
| 532 | 514 |
| 533 // The intersitial page currently shown if any, not own by this class | 515 // The intersitial page currently shown if any, not own by this class |
| 534 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 516 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
| 535 InterstitialPageImpl* interstitial_page_; | 517 InterstitialPageImpl* interstitial_page_; |
| 536 | 518 |
| 537 NotificationRegistrar registrar_; | 519 NotificationRegistrar registrar_; |
| 538 | 520 |
| 539 // PlzNavigate: Owns a navigation request that originated in that frame until | |
| 540 // it commits. | |
| 541 scoped_ptr<NavigationRequest> navigation_request_; | |
| 542 | |
| 543 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; | 521 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; |
| 544 | 522 |
| 545 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); | 523 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); |
| 546 }; | 524 }; |
| 547 | 525 |
| 548 } // namespace content | 526 } // namespace content |
| 549 | 527 |
| 550 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 528 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
| OLD | NEW |