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. OnBeginNavigation is called |
315 void OnBeginNavigation(const FrameHostMsg_BeginNavigation_Params& params); | 327 // direclty by RequestNavigation when there is no live-renderer. Otherwise, it |
Charlie Reis
2014/08/12 19:04:50
nit: directly
nit: no hyphen in live renderer
clamy
2014/08/13 13:27:24
Done.
| |
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, | |
nasko
2014/08/13 00:08:00
nit: it will be nice to put all PlzNavigate method
clamy
2014/08/13 13:27:24
Done.
| |
332 const NavigationEntryImpl& entry); | |
316 | 333 |
317 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy | 334 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy |
318 // that has the given SiteInstance and is associated with this | 335 // that has the given SiteInstance and is associated with this |
319 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. | 336 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. |
320 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); | 337 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); |
321 | 338 |
339 // PlzNavigate: Called when a navigation request has received a response, to | |
340 // select a renderer to use for the navigation. | |
341 void CommitNavigation(const NavigationBeforeCommitInfo& info); | |
342 | |
322 private: | 343 private: |
323 friend class RenderFrameHostManagerTest; | 344 friend class RenderFrameHostManagerTest; |
324 friend class TestWebContents; | 345 friend class TestWebContents; |
325 | 346 |
326 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, | 347 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, |
327 CreateCrossProcessSubframeProxies); | 348 CreateCrossProcessSubframeProxies); |
328 | 349 |
329 // Tracks information about a navigation while a cross-process transition is | 350 // 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. | 351 // in progress, in case we need to transfer it to a new RenderFrameHost. |
331 // When a request is being transferred, deleting the PendingNavigationParams, | 352 // 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( | 416 bool ShouldSwapBrowsingInstancesForNavigation( |
396 const NavigationEntry* current_entry, | 417 const NavigationEntry* current_entry, |
397 const NavigationEntryImpl* new_entry) const; | 418 const NavigationEntryImpl* new_entry) const; |
398 | 419 |
399 // Returns true if it is safe to reuse the current WebUI when navigating from | 420 // Returns true if it is safe to reuse the current WebUI when navigating from |
400 // |current_entry| to |new_entry|. | 421 // |current_entry| to |new_entry|. |
401 bool ShouldReuseWebUI( | 422 bool ShouldReuseWebUI( |
402 const NavigationEntry* current_entry, | 423 const NavigationEntry* current_entry, |
403 const NavigationEntryImpl* new_entry) const; | 424 const NavigationEntryImpl* new_entry) const; |
404 | 425 |
405 // Returns an appropriate SiteInstance object for the given NavigationEntry, | 426 // Returns the SiteInstance to use for the navigation. |
406 // possibly reusing the current SiteInstance. If --process-per-tab is used, | 427 SiteInstance* GetSiteInstanceForNavigation(const NavigationEntryImpl& entry); |
407 // this is only called when ShouldSwapBrowsingInstancesForNavigation returns | 428 |
408 // true. | 429 // Helper function that returns an appropriate SiteInstance object for the |
430 // given NavigationEntry, possibly reusing the current SiteInstance. If | |
431 // --process-per-tab is used, this is only called when | |
432 // ShouldSwapBrowsingInstancesForNavigation returns true. Caller should use | |
433 // GetSiteInstanceForNavigation. | |
409 SiteInstance* GetSiteInstanceForEntry( | 434 SiteInstance* GetSiteInstanceForEntry( |
410 const NavigationEntryImpl& entry, | 435 const NavigationEntryImpl& entry, |
411 SiteInstance* current_instance, | 436 SiteInstance* current_instance, |
412 bool force_browsing_instance_swap); | 437 bool force_browsing_instance_swap); |
413 | 438 |
439 // Creates a new RenderFrameHostImpl for the |new_instance| while respecting | |
440 // the opener route if needed and stores it in pending_render_frame_host_. | |
441 void CreateRenderFrameHostForNewSiteInstance( | |
442 SiteInstance* old_instance, | |
443 SiteInstance* new_instance, | |
444 bool is_main_frame); | |
445 | |
414 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. | 446 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. |
415 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, | 447 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, |
416 int view_routing_id, | 448 int view_routing_id, |
417 int frame_routing_id, | 449 int frame_routing_id, |
418 bool swapped_out, | 450 bool swapped_out, |
419 bool hidden); | 451 bool hidden); |
420 | 452 |
421 // Sets up the necessary state for a new RenderViewHost with the given opener, | 453 // 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 | 454 // 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 | 455 // with the given |proxy_routing_id|, which is used to route IPC messages when |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 typedef base::hash_map<int32, linked_ptr<RenderFrameHostImpl> > | 554 typedef base::hash_map<int32, linked_ptr<RenderFrameHostImpl> > |
523 RFHPendingDeleteMap; | 555 RFHPendingDeleteMap; |
524 RFHPendingDeleteMap pending_delete_hosts_; | 556 RFHPendingDeleteMap pending_delete_hosts_; |
525 | 557 |
526 // The intersitial page currently shown if any, not own by this class | 558 // The intersitial page currently shown if any, not own by this class |
527 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 559 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
528 InterstitialPageImpl* interstitial_page_; | 560 InterstitialPageImpl* interstitial_page_; |
529 | 561 |
530 NotificationRegistrar registrar_; | 562 NotificationRegistrar registrar_; |
531 | 563 |
532 // Owns a navigation request that originated in that frame until it commits. | 564 // PlzNavigate: Owns a navigation request that originated in that frame until |
565 // it commits. | |
533 scoped_ptr<NavigationRequest> navigation_request_; | 566 scoped_ptr<NavigationRequest> navigation_request_; |
534 | 567 |
535 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; | 568 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; |
536 | 569 |
537 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); | 570 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); |
538 }; | 571 }; |
539 | 572 |
540 } // namespace content | 573 } // namespace content |
541 | 574 |
542 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 575 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
OLD | NEW |