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 | 19 |
20 struct FrameHostMsg_BeginNavigation_Params; | 20 struct FrameHostMsg_BeginNavigation_Params; |
21 struct FrameMsg_Navigate_Params; | |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 class BrowserContext; | 24 class BrowserContext; |
24 class CrossProcessFrameConnector; | 25 class CrossProcessFrameConnector; |
25 class CrossSiteTransferringRequest; | 26 class CrossSiteTransferringRequest; |
26 class InterstitialPageImpl; | 27 class InterstitialPageImpl; |
27 class FrameTreeNode; | 28 class FrameTreeNode; |
28 class NavigationControllerImpl; | 29 class NavigationControllerImpl; |
29 class NavigationEntry; | 30 class NavigationEntry; |
30 class NavigationEntryImpl; | 31 class NavigationEntryImpl; |
31 class NavigationRequest; | 32 class NavigationRequest; |
32 class RenderFrameHost; | 33 class RenderFrameHost; |
33 class RenderFrameHostDelegate; | 34 class RenderFrameHostDelegate; |
34 class RenderFrameHost; | 35 class RenderFrameHost; |
35 class RenderFrameHostImpl; | 36 class RenderFrameHostImpl; |
36 class RenderFrameHostManagerTest; | 37 class RenderFrameHostManagerTest; |
37 class RenderFrameProxyHost; | 38 class RenderFrameProxyHost; |
38 class RenderViewHost; | 39 class RenderViewHost; |
39 class RenderViewHostImpl; | 40 class RenderViewHostImpl; |
40 class RenderWidgetHostDelegate; | 41 class RenderWidgetHostDelegate; |
41 class RenderWidgetHostView; | 42 class RenderWidgetHostView; |
42 class TestWebContents; | 43 class TestWebContents; |
43 class WebUIImpl; | 44 class WebUIImpl; |
45 struct NavigationBeforeCommitInfo; | |
44 | 46 |
45 // Manages RenderFrameHosts for a FrameTreeNode. This class acts as a state | 47 // Manages RenderFrameHosts for a FrameTreeNode. This class acts as a state |
46 // machine to make cross-process navigations in a frame possible. | 48 // machine to make cross-process navigations in a frame possible. |
47 class CONTENT_EXPORT RenderFrameHostManager : public NotificationObserver { | 49 class CONTENT_EXPORT RenderFrameHostManager : public NotificationObserver { |
48 public: | 50 public: |
49 // Functions implemented by our owner that we need. | 51 // Functions implemented by our owner that we need. |
50 // | 52 // |
51 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl | 53 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl |
52 // that are required to run this class. The design should probably be better | 54 // that are required to run this class. The design should probably be better |
53 // such that these are more clear. | 55 // such that these are more clear. |
54 // | 56 // |
55 // There is additional complexity that some of the functions we need in | 57 // There is additional complexity that some of the functions we need in |
56 // WebContentsImpl are inherited and non-virtual. These are named with | 58 // WebContentsImpl are inherited and non-virtual. These are named with |
57 // "RenderManager" so that the duplicate implementation of them will be clear. | 59 // "RenderManager" so that the duplicate implementation of them will be clear. |
60 // | |
61 // Functions and parameters whose description are prefixed by PlzNavigate are | |
62 // part of a navigation refactoring project, currently behind the | |
63 // enable-browser-side-navigation flag. The idea is to move the logic behind | |
64 // driving navigations from the renderer to the browser. | |
58 class CONTENT_EXPORT Delegate { | 65 class CONTENT_EXPORT Delegate { |
59 public: | 66 public: |
60 // Initializes the given renderer if necessary and creates the view ID | 67 // Initializes the given renderer if necessary and creates the view ID |
61 // corresponding to this view host. If this method is not called and the | 68 // corresponding to this view host. If this method is not called and the |
62 // process is not shared, then the WebContentsImpl will act as though the | 69 // process is not shared, then the WebContentsImpl will act as though the |
63 // renderer is not running (i.e., it will render "sad tab"). This method is | 70 // renderer is not running (i.e., it will render "sad tab"). This method is |
64 // automatically called from LoadURL. |for_main_frame_navigation| indicates | 71 // automatically called from LoadURL. |for_main_frame_navigation| indicates |
65 // whether this RenderViewHost is used to render a top-level frame, so the | 72 // whether this RenderViewHost is used to render a top-level frame, so the |
66 // appropriate RenderWidgetHostView type is used. | 73 // appropriate RenderWidgetHostView type is used. |
67 virtual bool CreateRenderViewForRenderManager( | 74 virtual bool CreateRenderViewForRenderManager( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 // Sets the pending Web UI for the pending navigation, ensuring that the | 191 // Sets the pending Web UI for the pending navigation, ensuring that the |
185 // bindings are appropriate for the given NavigationEntry. | 192 // bindings are appropriate for the given NavigationEntry. |
186 void SetPendingWebUI(const NavigationEntryImpl& entry); | 193 void SetPendingWebUI(const NavigationEntryImpl& entry); |
187 | 194 |
188 // Called when we want to instruct the renderer to navigate to the given | 195 // Called when we want to instruct the renderer to navigate to the given |
189 // navigation entry. It may create a new RenderFrameHost or re-use an existing | 196 // navigation entry. It may create a new RenderFrameHost or re-use an existing |
190 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one | 197 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one |
191 // could not be created. | 198 // could not be created. |
192 RenderFrameHostImpl* Navigate(const NavigationEntryImpl& entry); | 199 RenderFrameHostImpl* Navigate(const NavigationEntryImpl& entry); |
193 | 200 |
201 // PlzNavigate: sends a RequestNavigation IPC to the renderer to ask it to | |
202 // navigate. If no live renderer is present, then the navigation request will | |
203 // be sent directly to the ResourceDispatcherHost. | |
204 bool RequestNavigation(const NavigationEntryImpl& entry, | |
205 const FrameMsg_Navigate_Params& navigate_params); | |
206 | |
194 // Instructs the various live views to stop. Called when the user directed the | 207 // Instructs the various live views to stop. Called when the user directed the |
195 // page to stop loading. | 208 // page to stop loading. |
196 void Stop(); | 209 void Stop(); |
197 | 210 |
198 // Notifies the regular and pending RenderViewHosts that a load is or is not | 211 // Notifies the regular and pending RenderViewHosts that a load is or is not |
199 // happening. Even though the message is only for one of them, we don't know | 212 // happening. Even though the message is only for one of them, we don't know |
200 // which one so we tell both. | 213 // which one so we tell both. |
201 void SetIsLoading(bool is_loading); | 214 void SetIsLoading(bool is_loading); |
202 | 215 |
203 // Whether to close the tab or not when there is a hang during an unload | 216 // Whether to close the tab or not when there is a hang during an unload |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 void SwappedOut(RenderFrameHostImpl* render_frame_host); | 256 void SwappedOut(RenderFrameHostImpl* render_frame_host); |
244 | 257 |
245 // Called when a renderer's frame navigates. | 258 // Called when a renderer's frame navigates. |
246 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host); | 259 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host); |
247 | 260 |
248 // Called when a renderer sets its opener to null. | 261 // Called when a renderer sets its opener to null. |
249 void DidDisownOpener(RenderViewHost* render_view_host); | 262 void DidDisownOpener(RenderViewHost* render_view_host); |
250 | 263 |
251 // Helper method to create and initialize a RenderFrameHost. If |swapped_out| | 264 // Helper method to create and initialize a RenderFrameHost. If |swapped_out| |
252 // is true, it will be initially placed on the swapped out hosts list. | 265 // is true, it will be initially placed on the swapped out hosts list. |
253 // Otherwise, it will be used for a pending cross-site navigation. | |
254 // Returns the routing id of the *view* associated with the frame. | 266 // Returns the routing id of the *view* associated with the frame. |
255 int CreateRenderFrame(SiteInstance* instance, | 267 int CreateRenderFrame(SiteInstance* instance, |
256 int opener_route_id, | 268 int opener_route_id, |
257 bool swapped_out, | 269 bool swapped_out, |
258 bool for_main_frame_navigation, | 270 bool for_main_frame_navigation, |
259 bool hidden); | 271 bool hidden); |
260 | 272 |
261 // Helper method to create and initialize a RenderFrameProxyHost and return | 273 // Helper method to create and initialize a RenderFrameProxyHost and return |
262 // its routing id. | 274 // its routing id. |
263 int CreateRenderFrameProxy(SiteInstance* instance); | 275 int CreateRenderFrameProxy(SiteInstance* instance); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 void SwapOutOldPage(); | 316 void SwapOutOldPage(); |
305 | 317 |
306 // Deletes a RenderFrameHost that was pending shutdown. | 318 // Deletes a RenderFrameHost that was pending shutdown. |
307 void ClearPendingShutdownRFHForSiteInstance(int32 site_instance_id, | 319 void ClearPendingShutdownRFHForSiteInstance(int32 site_instance_id, |
308 RenderFrameHostImpl* rfh); | 320 RenderFrameHostImpl* rfh); |
309 | 321 |
310 // Deletes any proxy hosts associated with this node. Used during destruction | 322 // Deletes any proxy hosts associated with this node. Used during destruction |
311 // of WebContentsImpl. | 323 // of WebContentsImpl. |
312 void ResetProxyHosts(); | 324 void ResetProxyHosts(); |
313 | 325 |
314 // Used to start a navigation, part of browser-side navigation project. | 326 // PlzNavigate: Used to start a navigation. |
Charlie Reis
2014/08/08 20:25:29
Let's explain whether this happens before or after
clamy
2014/08/12 12:13:16
Done.
| |
315 void OnBeginNavigation(const FrameHostMsg_BeginNavigation_Params& params); | 327 void OnBeginNavigation(const FrameHostMsg_BeginNavigation_Params& params, |
328 const NavigationEntryImpl& entry); | |
316 | 329 |
317 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy | 330 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy |
318 // that has the given SiteInstance and is associated with this | 331 // that has the given SiteInstance and is associated with this |
319 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. | 332 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. |
320 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); | 333 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); |
321 | 334 |
335 // PlzNavigate: Used to signal the commit of a navigation request. | |
Charlie Reis
2014/08/08 20:25:29
In retrospect, this comment isn't very clear, part
clamy
2014/08/12 12:13:16
Is the comment now clearer?
| |
336 void CommitNavigation(const NavigationBeforeCommitInfo& info); | |
337 | |
322 private: | 338 private: |
323 friend class RenderFrameHostManagerTest; | 339 friend class RenderFrameHostManagerTest; |
324 friend class TestWebContents; | 340 friend class TestWebContents; |
325 | 341 |
326 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, | 342 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, |
327 CreateCrossProcessSubframeProxies); | 343 CreateCrossProcessSubframeProxies); |
328 | 344 |
329 // Tracks information about a navigation while a cross-process transition is | 345 // Tracks information about a navigation while a cross-process transition is |
330 // in progress, in case we need to transfer it to a new RenderFrameHost. | 346 // in progress, in case we need to transfer it to a new RenderFrameHost. |
331 // When a request is being transferred, deleting the PendingNavigationParams, | 347 // When a request is being transferred, deleting the PendingNavigationParams, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 bool ShouldSwapBrowsingInstancesForNavigation( | 411 bool ShouldSwapBrowsingInstancesForNavigation( |
396 const NavigationEntry* current_entry, | 412 const NavigationEntry* current_entry, |
397 const NavigationEntryImpl* new_entry) const; | 413 const NavigationEntryImpl* new_entry) const; |
398 | 414 |
399 // Returns true if it is safe to reuse the current WebUI when navigating from | 415 // Returns true if it is safe to reuse the current WebUI when navigating from |
400 // |current_entry| to |new_entry|. | 416 // |current_entry| to |new_entry|. |
401 bool ShouldReuseWebUI( | 417 bool ShouldReuseWebUI( |
402 const NavigationEntry* current_entry, | 418 const NavigationEntry* current_entry, |
403 const NavigationEntryImpl* new_entry) const; | 419 const NavigationEntryImpl* new_entry) const; |
404 | 420 |
405 // Returns an appropriate SiteInstance object for the given NavigationEntry, | 421 // Returns the SiteInstance to use for the navigation. |
406 // possibly reusing the current SiteInstance. If --process-per-tab is used, | 422 SiteInstance* GetSiteInstanceForNavigation(const NavigationEntryImpl& entry); |
407 // this is only called when ShouldSwapBrowsingInstancesForNavigation returns | 423 |
408 // true. | 424 // Helper function that returns an appropriate SiteInstance object for the |
425 // given NavigationEntry, possibly reusing the current SiteInstance. If | |
426 // --process-per-tab is used, this is only called when | |
427 // ShouldSwapBrowsingInstancesForNavigation returns true. Caller should use | |
428 // GetSiteInstanceForNavigation. | |
409 SiteInstance* GetSiteInstanceForEntry( | 429 SiteInstance* GetSiteInstanceForEntry( |
410 const NavigationEntryImpl& entry, | 430 const NavigationEntryImpl& entry, |
411 SiteInstance* current_instance, | 431 SiteInstance* current_instance, |
412 bool force_browsing_instance_swap); | 432 bool force_browsing_instance_swap); |
413 | 433 |
434 // Creates a new RenderFrameHostImpl for the |new_instance| while respecting | |
435 // the opener route if needed and stores it in pending_render_frame_host_. | |
436 // Also returns a pointer to the newly created RFH. | |
437 RenderFrameHostImpl* CreateRenderFrameHostForNewSiteInstance( | |
438 SiteInstance* old_instance, | |
439 SiteInstance* new_instance, | |
440 bool is_main_frame); | |
441 | |
414 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. | 442 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. |
415 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, | 443 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, |
416 int view_routing_id, | 444 int view_routing_id, |
417 int frame_routing_id, | 445 int frame_routing_id, |
418 bool swapped_out, | 446 bool swapped_out, |
419 bool hidden); | 447 bool hidden); |
420 | 448 |
421 // Sets up the necessary state for a new RenderViewHost with the given opener, | 449 // Sets up the necessary state for a new RenderViewHost with the given opener, |
422 // if necessary. It creates a RenderFrameProxy in the target renderer process | 450 // if necessary. It creates a RenderFrameProxy in the target renderer process |
423 // with the given |proxy_routing_id|, which is used to route IPC messages when | 451 // with the given |proxy_routing_id|, which is used to route IPC messages when |
424 // in swapped out state. Returns early if the RenderViewHost has already been | 452 // in swapped out state. Returns early if the RenderViewHost has already been |
425 // initialized for another RenderFrameHost. | 453 // initialized for another RenderFrameHost. |
426 // TODO(creis): opener_route_id is currently for the RenderViewHost but should | 454 // TODO(creis): opener_route_id is currently for the RenderViewHost but should |
427 // be for the RenderFrame, since frames can have openers. | 455 // be for the RenderFrame, since frames can have openers. |
428 bool InitRenderView(RenderViewHost* render_view_host, | 456 bool InitRenderView(RenderViewHost* render_view_host, |
429 int opener_route_id, | 457 int opener_route_id, |
430 int proxy_routing_id, | 458 int proxy_routing_id, |
431 bool for_main_frame_navigation); | 459 bool for_main_frame_navigation); |
432 | 460 |
433 // Initialization for RenderFrameHost uses the same sequence as InitRenderView | 461 // Initialization for RenderFrameHost uses the same sequence as InitRenderView |
434 // above. | 462 // above. |
435 bool InitRenderFrame(RenderFrameHost* render_frame_host); | 463 bool InitRenderFrame(RenderFrameHost* render_frame_host); |
436 | 464 |
465 // Initializes |dest_render_frame_host| and |render_frame_host_| if necessary | |
466 // before navigating. | |
467 bool InitRenderFrameHostsBeforeNavigation( | |
468 RenderFrameHostImpl* dest_render_frame_host); | |
469 | |
437 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this | 470 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this |
438 // doesn't require the pending render_frame_host_ pointer to be non-NULL, | 471 // doesn't require the pending render_frame_host_ pointer to be non-NULL, |
439 // since there could be Web UI switching as well. Call this for every commit. | 472 // since there could be Web UI switching as well. Call this for every commit. |
440 void CommitPending(); | 473 void CommitPending(); |
441 | 474 |
442 // Shutdown all RenderFrameProxyHosts in a SiteInstance. This is called to | 475 // Shutdown all RenderFrameProxyHosts in a SiteInstance. This is called to |
443 // shutdown frames when all the frames in a SiteInstance are confirmed to be | 476 // shutdown frames when all the frames in a SiteInstance are confirmed to be |
444 // swapped out. | 477 // swapped out. |
445 void ShutdownRenderFrameProxyHostsInSiteInstance(int32 site_instance_id); | 478 void ShutdownRenderFrameProxyHostsInSiteInstance(int32 site_instance_id); |
446 | 479 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 typedef base::hash_map<int32, linked_ptr<RenderFrameHostImpl> > | 551 typedef base::hash_map<int32, linked_ptr<RenderFrameHostImpl> > |
519 RFHPendingDeleteMap; | 552 RFHPendingDeleteMap; |
520 RFHPendingDeleteMap pending_delete_hosts_; | 553 RFHPendingDeleteMap pending_delete_hosts_; |
521 | 554 |
522 // The intersitial page currently shown if any, not own by this class | 555 // The intersitial page currently shown if any, not own by this class |
523 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 556 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
524 InterstitialPageImpl* interstitial_page_; | 557 InterstitialPageImpl* interstitial_page_; |
525 | 558 |
526 NotificationRegistrar registrar_; | 559 NotificationRegistrar registrar_; |
527 | 560 |
528 // Owns a navigation request that originated in that frame until it commits. | 561 // PlzNavigate: Owns a navigation request that originated in that frame until |
562 // it commits. | |
529 scoped_ptr<NavigationRequest> navigation_request_; | 563 scoped_ptr<NavigationRequest> navigation_request_; |
530 | 564 |
531 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; | 565 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; |
532 | 566 |
533 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); | 567 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); |
534 }; | 568 }; |
535 | 569 |
536 } // namespace content | 570 } // namespace content |
537 | 571 |
538 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 572 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
OLD | NEW |