Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager.h

Issue 379143002: PlzNavigate: implement RequestNavigation in the no live renderer case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Charlie's comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 RenderFrameHostImpl; 35 class RenderFrameHostImpl;
35 class RenderFrameHostManagerTest; 36 class RenderFrameHostManagerTest;
36 class RenderFrameProxyHost; 37 class RenderFrameProxyHost;
37 class RenderViewHost; 38 class RenderViewHost;
38 class RenderViewHostImpl; 39 class RenderViewHostImpl;
39 class RenderWidgetHostDelegate; 40 class RenderWidgetHostDelegate;
40 class RenderWidgetHostView; 41 class RenderWidgetHostView;
41 class TestWebContents; 42 class TestWebContents;
42 class WebUIImpl; 43 class WebUIImpl;
44 struct NavigationBeforeCommitInfo;
43 45
44 // Manages RenderFrameHosts for a FrameTreeNode. This class acts as a state 46 // Manages RenderFrameHosts for a FrameTreeNode. This class acts as a state
45 // machine to make cross-process navigations in a frame possible. 47 // machine to make cross-process navigations in a frame possible.
46 class CONTENT_EXPORT RenderFrameHostManager : public NotificationObserver { 48 class CONTENT_EXPORT RenderFrameHostManager : public NotificationObserver {
47 public: 49 public:
48 // Functions implemented by our owner that we need. 50 // Functions implemented by our owner that we need.
49 // 51 //
50 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl 52 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl
51 // that are required to run this class. The design should probably be better 53 // that are required to run this class. The design should probably be better
52 // such that these are more clear. 54 // such that these are more clear.
53 // 55 //
54 // There is additional complexity that some of the functions we need in 56 // There is additional complexity that some of the functions we need in
55 // WebContentsImpl are inherited and non-virtual. These are named with 57 // WebContentsImpl are inherited and non-virtual. These are named with
56 // "RenderManager" so that the duplicate implementation of them will be clear. 58 // "RenderManager" so that the duplicate implementation of them will be clear.
59 //
60 // Functions and parameters whose description are prefixed by PlzNavigate are
61 // part of a navigation refactoring project, currently behind the
62 // enable-browser-side-navigation flag. The idea is to move the logic behind
63 // driving navigations from the renderer to the browser.
57 class CONTENT_EXPORT Delegate { 64 class CONTENT_EXPORT Delegate {
58 public: 65 public:
59 // Initializes the given renderer if necessary and creates the view ID 66 // Initializes the given renderer if necessary and creates the view ID
60 // corresponding to this view host. If this method is not called and the 67 // corresponding to this view host. If this method is not called and the
61 // process is not shared, then the WebContentsImpl will act as though the 68 // process is not shared, then the WebContentsImpl will act as though the
62 // renderer is not running (i.e., it will render "sad tab"). This method is 69 // renderer is not running (i.e., it will render "sad tab"). This method is
63 // automatically called from LoadURL. |for_main_frame| indicates whether 70 // automatically called from LoadURL. |for_main_frame| indicates whether
64 // this RenderViewHost is used to render a top-level frame, so the 71 // this RenderViewHost is used to render a top-level frame, so the
65 // appropriate RenderWidgetHostView type is used. 72 // appropriate RenderWidgetHostView type is used.
66 virtual bool CreateRenderViewForRenderManager( 73 virtual bool CreateRenderViewForRenderManager(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // Sets the pending Web UI for the pending navigation, ensuring that the 187 // Sets the pending Web UI for the pending navigation, ensuring that the
181 // bindings are appropriate for the given NavigationEntry. 188 // bindings are appropriate for the given NavigationEntry.
182 void SetPendingWebUI(const NavigationEntryImpl& entry); 189 void SetPendingWebUI(const NavigationEntryImpl& entry);
183 190
184 // Called when we want to instruct the renderer to navigate to the given 191 // Called when we want to instruct the renderer to navigate to the given
185 // navigation entry. It may create a new RenderFrameHost or re-use an existing 192 // navigation entry. It may create a new RenderFrameHost or re-use an existing
186 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one 193 // one. The RenderFrameHost to navigate will be returned. Returns NULL if one
187 // could not be created. 194 // could not be created.
188 RenderFrameHostImpl* Navigate(const NavigationEntryImpl& entry); 195 RenderFrameHostImpl* Navigate(const NavigationEntryImpl& entry);
189 196
197 // PlzNavigate: sends a RequestNavigation IPC to the renderer to ask it to
198 // navigate. If no live renderer is present, then the navigation request will
199 // be sent directly to the ResourceDispatcherHost.
200 bool RequestNavigation(const NavigationEntryImpl& entry,
201 const FrameMsg_Navigate_Params& navigate_params);
202
190 // Instructs the various live views to stop. Called when the user directed the 203 // Instructs the various live views to stop. Called when the user directed the
191 // page to stop loading. 204 // page to stop loading.
192 void Stop(); 205 void Stop();
193 206
194 // Notifies the regular and pending RenderViewHosts that a load is or is not 207 // Notifies the regular and pending RenderViewHosts that a load is or is not
195 // happening. Even though the message is only for one of them, we don't know 208 // happening. Even though the message is only for one of them, we don't know
196 // which one so we tell both. 209 // which one so we tell both.
197 void SetIsLoading(bool is_loading); 210 void SetIsLoading(bool is_loading);
198 211
199 // Whether to close the tab or not when there is a hang during an unload 212 // 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
239 void SwappedOut(RenderFrameHostImpl* render_frame_host); 252 void SwappedOut(RenderFrameHostImpl* render_frame_host);
240 253
241 // Called when a renderer's frame navigates. 254 // Called when a renderer's frame navigates.
242 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host); 255 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host);
243 256
244 // Called when a renderer sets its opener to null. 257 // Called when a renderer sets its opener to null.
245 void DidDisownOpener(RenderViewHost* render_view_host); 258 void DidDisownOpener(RenderViewHost* render_view_host);
246 259
247 // Helper method to create and initialize a RenderFrameHost. If |swapped_out| 260 // Helper method to create and initialize a RenderFrameHost. If |swapped_out|
248 // is true, it will be initially placed on the swapped out hosts list. 261 // is true, it will be initially placed on the swapped out hosts list.
262 // Else if |is_speculative| is true, then it will used as a speculatively
263 // spawned renderer in the PlzNavigate navigation refactoring project.
249 // Otherwise, it will be used for a pending cross-site navigation. 264 // Otherwise, it will be used for a pending cross-site navigation.
250 // Returns the routing id of the *view* associated with the frame. 265 // Returns the routing id of the *view* associated with the frame.
251 int CreateRenderFrame(SiteInstance* instance, 266 int CreateRenderFrame(SiteInstance* instance,
252 int opener_route_id, 267 int opener_route_id,
253 bool swapped_out, 268 bool swapped_out,
254 bool hidden); 269 bool hidden,
270 bool is_speculative);
255 271
256 // Sets the passed passed interstitial as the currently showing interstitial. 272 // Sets the passed passed interstitial as the currently showing interstitial.
257 // |interstitial_page| should be non NULL (use the remove_interstitial_page 273 // |interstitial_page| should be non NULL (use the remove_interstitial_page
258 // method to unset the interstitial) and no interstitial page should be set 274 // method to unset the interstitial) and no interstitial page should be set
259 // when there is already a non NULL interstitial page set. 275 // when there is already a non NULL interstitial page set.
260 void set_interstitial_page(InterstitialPageImpl* interstitial_page) { 276 void set_interstitial_page(InterstitialPageImpl* interstitial_page) {
261 DCHECK(!interstitial_page_ && interstitial_page); 277 DCHECK(!interstitial_page_ && interstitial_page);
262 interstitial_page_ = interstitial_page; 278 interstitial_page_ = interstitial_page;
263 } 279 }
264 280
(...skipping 30 matching lines...) Expand all
295 void SwapOutOldPage(); 311 void SwapOutOldPage();
296 312
297 // Deletes a RenderFrameHost that was pending shutdown. 313 // Deletes a RenderFrameHost that was pending shutdown.
298 void ClearPendingShutdownRFHForSiteInstance(int32 site_instance_id, 314 void ClearPendingShutdownRFHForSiteInstance(int32 site_instance_id,
299 RenderFrameHostImpl* rfh); 315 RenderFrameHostImpl* rfh);
300 316
301 // Deletes any proxy hosts associated with this node. Used during destruction 317 // Deletes any proxy hosts associated with this node. Used during destruction
302 // of WebContentsImpl. 318 // of WebContentsImpl.
303 void ResetProxyHosts(); 319 void ResetProxyHosts();
304 320
305 // Used to start a navigation, part of browser-side navigation project. 321 // PlzNavigate: Used to start a navigation.
306 void OnBeginNavigation(const FrameHostMsg_BeginNavigation_Params& params); 322 void OnBeginNavigation(const FrameHostMsg_BeginNavigation_Params& params);
307 323
324 // PlzNavigate: Used to signal the commit of a navigation request.
325 void CommitNavigation(const NavigationBeforeCommitInfo& info);
326
308 private: 327 private:
309 friend class RenderFrameHostManagerTest; 328 friend class RenderFrameHostManagerTest;
310 friend class TestWebContents; 329 friend class TestWebContents;
311 330
312 // Tracks information about a navigation while a cross-process transition is 331 // Tracks information about a navigation while a cross-process transition is
313 // in progress, in case we need to transfer it to a new RenderFrameHost. 332 // in progress, in case we need to transfer it to a new RenderFrameHost.
314 // When a request is being transferred, deleting the PendingNavigationParams, 333 // When a request is being transferred, deleting the PendingNavigationParams,
315 // and thus |cross_site_transferring_request|, will cancel the request being 334 // and thus |cross_site_transferring_request|, will cancel the request being
316 // transferred, unless its ReleaseRequest method has been called. 335 // transferred, unless its ReleaseRequest method has been called.
317 struct PendingNavigationParams { 336 struct PendingNavigationParams {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 406
388 // Returns an appropriate SiteInstance object for the given NavigationEntry, 407 // Returns an appropriate SiteInstance object for the given NavigationEntry,
389 // possibly reusing the current SiteInstance. If --process-per-tab is used, 408 // possibly reusing the current SiteInstance. If --process-per-tab is used,
390 // this is only called when ShouldSwapBrowsingInstancesForNavigation returns 409 // this is only called when ShouldSwapBrowsingInstancesForNavigation returns
391 // true. 410 // true.
392 SiteInstance* GetSiteInstanceForEntry( 411 SiteInstance* GetSiteInstanceForEntry(
393 const NavigationEntryImpl& entry, 412 const NavigationEntryImpl& entry,
394 SiteInstance* current_instance, 413 SiteInstance* current_instance,
395 bool force_browsing_instance_swap); 414 bool force_browsing_instance_swap);
396 415
416 // Creates a new RenderFrameHostImpl for the |new_instance| while respecting
417 // the opener route if needed and stores it in pending_render_frame_host_.
418 // Also returns a pointer to the newly created RFH.
419 // PlzNavigate: If |is_speculative| is true, then the newly created RFH will
420 // be stored in speculative_render_frame_host_.
421 RenderFrameHostImpl* CreateRenderFrameHostForNewSiteInstance(
422 SiteInstance* old_instance,
423 SiteInstance* new_instance,
424 bool is_speculative);
425
397 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. 426 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
398 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, 427 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance,
399 int view_routing_id, 428 int view_routing_id,
400 int frame_routing_id, 429 int frame_routing_id,
401 bool swapped_out, 430 bool swapped_out,
402 bool hidden); 431 bool hidden);
403 432
404 // Sets up the necessary state for a new RenderViewHost with the given opener, 433 // Sets up the necessary state for a new RenderViewHost with the given opener,
405 // if necessary. It creates a RenderFrameProxy in the target renderer process 434 // if necessary. It creates a RenderFrameProxy in the target renderer process
406 // with the given |proxy_routing_id|, which is used to route IPC messages when 435 // with the given |proxy_routing_id|, which is used to route IPC messages when
407 // in swapped out state. Returns early if the RenderViewHost has already been 436 // in swapped out state. Returns early if the RenderViewHost has already been
408 // initialized for another RenderFrameHost. 437 // initialized for another RenderFrameHost.
409 // TODO(creis): opener_route_id is currently for the RenderViewHost but should 438 // TODO(creis): opener_route_id is currently for the RenderViewHost but should
410 // be for the RenderFrame, since frames can have openers. 439 // be for the RenderFrame, since frames can have openers.
411 bool InitRenderView(RenderViewHost* render_view_host, 440 bool InitRenderView(RenderViewHost* render_view_host,
412 int opener_route_id, 441 int opener_route_id,
413 int proxy_routing_id, 442 int proxy_routing_id,
414 bool for_main_frame); 443 bool for_main_frame);
415 444
445 // Initializes |dest_render_frame_host| and |render_frame_host_| if necessary
446 // before navigating.
447 bool InitRenderFrameHostsBeforeNavigation(
448 RenderFrameHostImpl* dest_render_frame_host);
449
450 // Returns the SiteInstance to use for the navigation.
Charlie Reis 2014/07/30 23:37:33 I see-- this is a wrapper for GetSiteInstanceForEn
clamy 2014/08/05 11:52:44 Done.
451 SiteInstance* GetSiteInstanceForNavigation(const NavigationEntryImpl& entry);
452
416 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this 453 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
417 // doesn't require the pending render_frame_host_ pointer to be non-NULL, 454 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
418 // since there could be Web UI switching as well. Call this for every commit. 455 // since there could be Web UI switching as well. Call this for every commit.
419 void CommitPending(); 456 void CommitPending();
420 457
421 // Shutdown all RenderFrameHosts in a SiteInstance. This is called to shutdown 458 // Shutdown all RenderFrameHosts in a SiteInstance. This is called to shutdown
422 // frames when all the frames in a SiteInstance are confirmed to be swapped 459 // frames when all the frames in a SiteInstance are confirmed to be swapped
423 // out. 460 // out.
424 void ShutdownRenderFrameHostsInSiteInstance(int32 site_instance_id); 461 void ShutdownRenderFrameHostsInSiteInstance(int32 site_instance_id);
425 462
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // A RenderFrameHost used to load a cross-site page. This remains hidden 503 // A RenderFrameHost used to load a cross-site page. This remains hidden
467 // while a cross-site request is pending until it calls DidNavigate. It may 504 // while a cross-site request is pending until it calls DidNavigate. It may
468 // have an associated Web UI, in which case the Web UI pointer will be non- 505 // have an associated Web UI, in which case the Web UI pointer will be non-
469 // NULL. 506 // NULL.
470 // 507 //
471 // The |pending_web_ui_| may be non-NULL even when the 508 // The |pending_web_ui_| may be non-NULL even when the
472 // |pending_render_frame_host_| is NULL. This will happen when we're 509 // |pending_render_frame_host_| is NULL. This will happen when we're
473 // transitioning between two Web UI pages: the RFH won't be swapped, so the 510 // transitioning between two Web UI pages: the RFH won't be swapped, so the
474 // pending pointer will be unused, but there will be a pending Web UI 511 // pending pointer will be unused, but there will be a pending Web UI
475 // associated with the navigation. 512 // associated with the navigation.
513 //
514 // PlzNavigate: The pending_render_frame_host_ mechanism will not exist
515 // anymore. Instead the speculative_render_frame_host_ may be used.
476 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_; 516 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_;
477 517
478 // Tracks information about any current pending cross-process navigation. 518 // Tracks information about any current pending cross-process navigation.
479 scoped_ptr<PendingNavigationParams> pending_nav_params_; 519 scoped_ptr<PendingNavigationParams> pending_nav_params_;
480 520
481 // Tracks information about any navigation paused after receiving response 521 // Tracks information about any navigation paused after receiving response
482 // headers. 522 // headers.
483 scoped_ptr<GlobalRequestID> response_started_id_; 523 scoped_ptr<GlobalRequestID> response_started_id_;
484 524
525 // PlzNavigate: A RenderFrameHost speculatively created when receiving a
526 // navigation request. It should be used or deleted when the current
527 // navigation request commits.
528 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_;
529
485 // If either of these is non-NULL, the pending navigation is to a chrome: 530 // If either of these is non-NULL, the pending navigation is to a chrome:
486 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is 531 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is
487 // used for when they reference the same object. If either is non-NULL, the 532 // used for when they reference the same object. If either is non-NULL, the
488 // other should be NULL. 533 // other should be NULL.
489 scoped_ptr<WebUIImpl> pending_web_ui_; 534 scoped_ptr<WebUIImpl> pending_web_ui_;
490 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; 535 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_;
491 536
492 // A map of site instance ID to RenderFrameProxyHosts. 537 // A map of site instance ID to RenderFrameProxyHosts.
493 typedef base::hash_map<int32, RenderFrameProxyHost*> RenderFrameProxyHostMap; 538 typedef base::hash_map<int32, RenderFrameProxyHost*> RenderFrameProxyHostMap;
494 RenderFrameProxyHostMap proxy_hosts_; 539 RenderFrameProxyHostMap proxy_hosts_;
495 540
496 // A map of RenderFrameHosts pending shutdown. 541 // A map of RenderFrameHosts pending shutdown.
497 typedef base::hash_map<int32, linked_ptr<RenderFrameHostImpl> > 542 typedef base::hash_map<int32, linked_ptr<RenderFrameHostImpl> >
498 RFHPendingDeleteMap; 543 RFHPendingDeleteMap;
499 RFHPendingDeleteMap pending_delete_hosts_; 544 RFHPendingDeleteMap pending_delete_hosts_;
500 545
501 // The intersitial page currently shown if any, not own by this class 546 // The intersitial page currently shown if any, not own by this class
502 // (the InterstitialPage is self-owned, it deletes itself when hidden). 547 // (the InterstitialPage is self-owned, it deletes itself when hidden).
503 InterstitialPageImpl* interstitial_page_; 548 InterstitialPageImpl* interstitial_page_;
504 549
505 NotificationRegistrar registrar_; 550 NotificationRegistrar registrar_;
506 551
507 // Owns a navigation request that originated in that frame until it commits. 552 // PlzNavigate: Owns a navigation request that originated in that frame until
553 // it commits.
508 scoped_ptr<NavigationRequest> navigation_request_; 554 scoped_ptr<NavigationRequest> navigation_request_;
509 555
510 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; 556 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_;
511 557
512 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); 558 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager);
513 }; 559 };
514 560
515 } // namespace content 561 } // namespace content
516 562
517 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ 563 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698