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

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

Issue 30323002: [DRAFT] Create RenderFrameHostManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 1 month 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 | Annotate | Revision Log
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_VIEW_HOST_MANAGER_H_ 5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_VIEW_HOST_MANAGER_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_VIEW_HOST_MANAGER_H_ 6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_VIEW_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/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
17 #include "content/public/common/referrer.h" 17 #include "content/public/common/referrer.h"
18 18
19 19
20 namespace content { 20 namespace content {
21 class BrowserContext; 21 class BrowserContext;
22 class FrameTreeNode;
22 class InterstitialPageImpl; 23 class InterstitialPageImpl;
23 class NavigationControllerImpl; 24 class NavigationControllerImpl;
24 class NavigationEntry; 25 class NavigationEntry;
25 class NavigationEntryImpl; 26 class NavigationEntryImpl;
27 class RenderFrameHostImpl;
26 class RenderViewHost; 28 class RenderViewHost;
27 class RenderViewHostImpl; 29 class RenderViewHostImpl;
28 class RenderViewHostManagerTest; 30 class RenderViewHostManagerTest;
29 class RenderWidgetHostDelegate; 31 class RenderWidgetHostDelegate;
30 class RenderWidgetHostView; 32 class RenderWidgetHostView;
31 class TestWebContents; 33 class TestWebContents;
32 class WebUIImpl; 34 class WebUIImpl;
33 35
34 // Manages RenderViewHosts for a WebContentsImpl. Normally there is only one and 36 // Manages RenderViewHosts for a WebContentsImpl. Normally there is only one and
35 // it is easy to do. But we can also have transitions of processes (and hence 37 // it is easy to do. But we can also have transitions of processes (and hence
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 virtual ~Delegate() {} 109 virtual ~Delegate() {}
108 }; 110 };
109 111
110 // All three delegate pointers must be non-NULL and are not owned by this 112 // All three delegate pointers must be non-NULL and are not owned by this
111 // class. They must outlive this class. The RenderViewHostDelegate and 113 // class. They must outlive this class. The RenderViewHostDelegate and
112 // RenderWidgetHostDelegate are what will be installed into all 114 // RenderWidgetHostDelegate are what will be installed into all
113 // RenderViewHosts that are created. 115 // RenderViewHosts that are created.
114 // 116 //
115 // You must call Init() before using this class. 117 // You must call Init() before using this class.
116 RenderViewHostManager( 118 RenderViewHostManager(
119 FrameTreeNode* frame_tree_node,
117 RenderViewHostDelegate* render_view_delegate, 120 RenderViewHostDelegate* render_view_delegate,
118 RenderWidgetHostDelegate* render_widget_delegate, 121 RenderWidgetHostDelegate* render_widget_delegate,
119 Delegate* delegate); 122 Delegate* delegate);
120 virtual ~RenderViewHostManager(); 123 virtual ~RenderViewHostManager();
121 124
122 // For arguments, see WebContentsImpl constructor. 125 // For arguments, see WebContentsImpl constructor.
123 void Init(BrowserContext* browser_context, 126 void Init(BrowserContext* browser_context,
124 SiteInstance* site_instance, 127 SiteInstance* site_instance,
125 int routing_id, 128 int routing_id,
126 int main_frame_routing_id); 129 int main_frame_routing_id);
127 130
128 // Returns the currently active RenderViewHost. 131 // Returns the currently active RenderViewHost.
129 // 132 //
130 // This will be non-NULL between Init() and Shutdown(). You may want to NULL 133 // This will be non-NULL between Init() and Shutdown(). You may want to NULL
131 // check it in many cases, however. Windows can send us messages during the 134 // check it in many cases, however. Windows can send us messages during the
132 // destruction process after it has been shut down. 135 // destruction process after it has been shut down.
136 // TODO(creis): Change to RenderFrameHostImpl.
133 RenderViewHostImpl* current_host() const; 137 RenderViewHostImpl* current_host() const;
138 RenderFrameHostImpl* current_frame() const {
139 return render_frame_host_;
140 }
134 141
135 // Returns the view associated with the current RenderViewHost, or NULL if 142 // Returns the view associated with the current RenderViewHost, or NULL if
136 // there is no current one. 143 // there is no current one.
137 RenderWidgetHostView* GetRenderWidgetHostView() const; 144 RenderWidgetHostView* GetRenderWidgetHostView() const;
138 145
139 // Returns the pending render view host, or NULL if there is no pending one. 146 // Returns the pending render view host, or NULL if there is no pending one.
147 // TODO(creis): Change to RenderFrameHostImpl.
140 RenderViewHostImpl* pending_render_view_host() const; 148 RenderViewHostImpl* pending_render_view_host() const;
149 RenderFrameHostImpl* pending_render_frame_host() const;
141 150
142 // Returns the current committed Web UI or NULL if none applies. 151 // Returns the current committed Web UI or NULL if none applies.
143 WebUIImpl* web_ui() const { return web_ui_.get(); } 152 WebUIImpl* web_ui() const { return web_ui_.get(); }
144 153
145 // Returns the Web UI for the pending navigation, or NULL of none applies. 154 // Returns the Web UI for the pending navigation, or NULL of none applies.
146 WebUIImpl* pending_web_ui() const { 155 WebUIImpl* pending_web_ui() const {
147 return pending_web_ui_.get() ? pending_web_ui_.get() : 156 return pending_web_ui_.get() ? pending_web_ui_.get() :
148 pending_and_current_web_ui_.get(); 157 pending_and_current_web_ui_.get();
149 } 158 }
150 159
(...skipping 18 matching lines...) Expand all
169 178
170 // Whether to close the tab or not when there is a hang during an unload 179 // Whether to close the tab or not when there is a hang during an unload
171 // handler. If we are mid-crosssite navigation, then we should proceed 180 // handler. If we are mid-crosssite navigation, then we should proceed
172 // with the navigation instead of closing the tab. 181 // with the navigation instead of closing the tab.
173 bool ShouldCloseTabOnUnresponsiveRenderer(); 182 bool ShouldCloseTabOnUnresponsiveRenderer();
174 183
175 // The RenderViewHost has been swapped out, so we should resume the pending 184 // The RenderViewHost has been swapped out, so we should resume the pending
176 // network response and allow the pending RenderViewHost to commit. 185 // network response and allow the pending RenderViewHost to commit.
177 void SwappedOut(RenderViewHost* render_view_host); 186 void SwappedOut(RenderViewHost* render_view_host);
178 187
188 // The RenderFrameHost has been swapped out, so we should resume the pending
189 // network response and allow the pending RenderFrameHost to commit.
190 void SwappedOutFrame(RenderFrameHostImpl* render_frame_host);
191
179 // Called when a renderer's main frame navigates. 192 // Called when a renderer's main frame navigates.
180 void DidNavigateMainFrame(RenderViewHost* render_view_host); 193 void DidNavigateMainFrame(RenderViewHost* render_view_host);
181 194
182 // Called when a renderer sets its opener to null. 195 // Called when a renderer sets its opener to null.
183 void DidDisownOpener(RenderViewHost* render_view_host); 196 void DidDisownOpener(RenderViewHost* render_view_host);
184 197
185 // Helper method to create a RenderViewHost. If |swapped_out| is true, it 198 // Helper method to create a RenderViewHost. If |swapped_out| is true, it
186 // will be initially placed on the swapped out hosts list. Otherwise, it 199 // will be initially placed on the swapped out hosts list. Otherwise, it
187 // will be used for a pending cross-site navigation. 200 // will be used for a pending cross-site navigation.
188 int CreateRenderView(SiteInstance* instance, 201 int CreateRenderFrame(SiteInstance* instance,
189 int opener_route_id, 202 int opener_route_id,
190 bool swapped_out, 203 bool swapped_out,
191 bool hidden); 204 bool hidden);
192 205
193 // Called when a provisional load on the given renderer is aborted. 206 // Called when a provisional load on the given renderer is aborted.
194 void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host); 207 void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host);
195 208
196 // Sets the passed passed interstitial as the currently showing interstitial. 209 // Sets the passed passed interstitial as the currently showing interstitial.
197 // |interstitial_page| should be non NULL (use the remove_interstitial_page 210 // |interstitial_page| should be non NULL (use the remove_interstitial_page
198 // method to unset the interstitial) and no interstitial page should be set 211 // method to unset the interstitial) and no interstitial page should be set
199 // when there is already a non NULL interstitial page set. 212 // when there is already a non NULL interstitial page set.
200 void set_interstitial_page(InterstitialPageImpl* interstitial_page) { 213 void set_interstitial_page(InterstitialPageImpl* interstitial_page) {
201 DCHECK(!interstitial_page_ && interstitial_page); 214 DCHECK(!interstitial_page_ && interstitial_page);
(...skipping 25 matching lines...) Expand all
227 int64 frame_id) OVERRIDE; 240 int64 frame_id) OVERRIDE;
228 241
229 // NotificationObserver implementation. 242 // NotificationObserver implementation.
230 virtual void Observe(int type, 243 virtual void Observe(int type,
231 const NotificationSource& source, 244 const NotificationSource& source,
232 const NotificationDetails& details) OVERRIDE; 245 const NotificationDetails& details) OVERRIDE;
233 246
234 // Called when a RenderViewHost is about to be deleted. 247 // Called when a RenderViewHost is about to be deleted.
235 void RenderViewDeleted(RenderViewHost* rvh); 248 void RenderViewDeleted(RenderViewHost* rvh);
236 249
237 // Returns whether the given RenderViewHost is on the list of swapped out 250 // Returns whether the given RenderFrameHost is on the list of swapped out
238 // RenderViewHosts. 251 // RenderFrameHosts.
239 bool IsOnSwappedOutList(RenderViewHost* rvh) const; 252 bool IsRVHOnSwappedOutList(RenderViewHostImpl* rvh) const;
253 bool IsOnSwappedOutList(RenderFrameHostImpl* rfh) const;
240 254
241 // Returns the swapped out RenderViewHost for the given SiteInstance, if any. 255 // Returns the swapped out RenderViewHost for the given SiteInstance, if any.
242 RenderViewHostImpl* GetSwappedOutRenderViewHost(SiteInstance* instance); 256 RenderViewHostImpl* GetSwappedOutRenderViewHost(SiteInstance* instance) const;
257 RenderFrameHostImpl* GetSwappedOutRenderFrameHost(
258 SiteInstance* instance) const;
243 259
244 // Runs the unload handler in the current page, when we know that a pending 260 // Runs the unload handler in the current page, when we know that a pending
245 // cross-process navigation is going to commit. We may initiate a transfer 261 // cross-process navigation is going to commit. We may initiate a transfer
246 // to a new process after this completes or times out. 262 // to a new process after this completes or times out.
247 void SwapOutOldPage(); 263 void SwapOutOldPage();
248 264
249 private: 265 private:
250 friend class RenderViewHostManagerTest; 266 friend class RenderViewHostManagerTest;
251 friend class TestWebContents; 267 friend class TestWebContents;
252 268
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 const NavigationEntryImpl* new_entry) const; 324 const NavigationEntryImpl* new_entry) const;
309 325
310 // Returns an appropriate SiteInstance object for the given NavigationEntry, 326 // Returns an appropriate SiteInstance object for the given NavigationEntry,
311 // possibly reusing the current SiteInstance. 327 // possibly reusing the current SiteInstance.
312 // Never called if --process-per-tab is used. 328 // Never called if --process-per-tab is used.
313 SiteInstance* GetSiteInstanceForEntry( 329 SiteInstance* GetSiteInstanceForEntry(
314 const NavigationEntryImpl& entry, 330 const NavigationEntryImpl& entry,
315 SiteInstance* curr_instance); 331 SiteInstance* curr_instance);
316 332
317 // Sets up the necessary state for a new RenderViewHost with the given opener. 333 // Sets up the necessary state for a new RenderViewHost with the given opener.
318 bool InitRenderView(RenderViewHost* render_view_host, int opener_route_id); 334 // This also initializes the RenderView if necessary.
335 // TODO(creis): opener_route_id is currently for the RenderView but should be
336 // the RenderFrame, since frames can have openers.
337 bool InitRenderView(RenderViewHost* render_view_host,
338 int opener_route_id);
319 339
320 // Sets the pending RenderViewHost/WebUI to be the active one. Note that this 340 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
321 // doesn't require the pending render_view_host_ pointer to be non-NULL, since 341 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
322 // there could be Web UI switching as well. Call this for every commit. 342 // since there could be Web UI switching as well. Call this for every commit.
323 void CommitPending(); 343 void CommitPending();
324 344
325 // Shutdown all RenderViewHosts in a SiteInstance. This is called 345 // Shutdown all RenderFrameHosts in a SiteInstance. This is called to shutdown
326 // to shutdown views when all the views in a SiteInstance are 346 // frames when all the views in a SiteInstance are confirmed to be swapped
327 // confirmed to be swapped out. 347 // out.
328 void ShutdownRenderViewHostsInSiteInstance(int32 site_instance_id); 348 void ShutdownRenderFrameHostsInSiteInstance(int32 site_instance_id);
329 349
330 // Helper method to terminate the pending RenderViewHost. 350 // Helper method to terminate the pending RenderViewHost.
331 void CancelPending(); 351 void CancelPending();
332 352
333 RenderViewHostImpl* UpdateRendererStateForNavigate( 353 RenderFrameHostImpl* UpdateRendererStateForNavigate(
334 const NavigationEntryImpl& entry); 354 const NavigationEntryImpl& entry);
335 355
336 // Called when a renderer process is starting to close. We should not 356 // Called when a renderer process is starting to close. We should not
337 // schedule new navigations in its swapped out RenderViewHosts after this. 357 // schedule new navigations in its swapped out RenderFrameHosts after this.
338 void RendererProcessClosing(RenderProcessHost* render_process_host); 358 void RendererProcessClosing(RenderProcessHost* render_process_host);
339 359
360 // For use in creating RenderFrameHosts.
361 // TODO(creis): Feels awkward to have pointers in both directions. Maybe use
362 // an ID here instead?
363 FrameTreeNode* frame_tree_node_;
364
340 // Our delegate, not owned by us. Guaranteed non-NULL. 365 // Our delegate, not owned by us. Guaranteed non-NULL.
341 Delegate* delegate_; 366 Delegate* delegate_;
342 367
343 // Whether a navigation requiring different RenderView's is pending. This is 368 // Whether a navigation requiring different RenderFrames is pending. This is
344 // either cross-site request is (in the new process model), or when required 369 // either for cross-site requests or when required for the view type (like
345 // for the view type (like view source versus not). 370 // WebUI).
346 bool cross_navigation_pending_; 371 bool cross_navigation_pending_;
347 372
348 // Implemented by the owner of this class, these delegates are installed into 373 // Implemented by the owner of this class. These delegates are installed into
349 // all the RenderViewHosts that we create. 374 // all the RenderViewHosts that we create.
350 RenderViewHostDelegate* render_view_delegate_; 375 RenderViewHostDelegate* render_view_delegate_;
351 RenderWidgetHostDelegate* render_widget_delegate_; 376 RenderWidgetHostDelegate* render_widget_delegate_;
352 377
353 // Our RenderView host and its associated Web UI (if any, will be NULL for 378 // Our RenderFrameHost and its associated Web UI (if any, will be NULL for
354 // non-DOM-UI pages). This object is responsible for all communication with 379 // non-Web-UI pages). This object is responsible for all communication with
355 // a child RenderView instance. 380 // a child RenderFrame instance.
356 RenderViewHostImpl* render_view_host_; 381 // For now, RenderFrameHost keeps a RenderViewHost in its SiteInstance alive.
382 // Eventually, RenderViewHost will be replaced with a page context.
383 RenderFrameHostImpl* render_frame_host_;
357 scoped_ptr<WebUIImpl> web_ui_; 384 scoped_ptr<WebUIImpl> web_ui_;
358 385
359 // A RenderViewHost used to load a cross-site page. This remains hidden 386 // A RenderFrameHost used to load a cross-site page. This remains hidden
360 // while a cross-site request is pending until it calls DidNavigate. It may 387 // while a cross-site request is pending until it calls DidNavigate. It may
361 // have an associated Web UI, in which case the Web UI pointer will be non- 388 // have an associated Web UI, in which case the Web UI pointer will be non-
362 // NULL. 389 // NULL.
363 // 390 //
364 // The |pending_web_ui_| may be non-NULL even when the 391 // The |pending_web_ui_| may be non-NULL even when the
365 // |pending_render_view_host_| is NULL. This will happen when we're 392 // |pending_render_view_host_| is NULL. This will happen when we're
366 // transitioning between two Web UI pages: the RVH won't be swapped, so the 393 // transitioning between two Web UI pages: the RFH won't be swapped, so the
367 // pending pointer will be unused, but there will be a pending Web UI 394 // pending pointer will be unused, but there will be a pending Web UI
368 // associated with the navigation. 395 // associated with the navigation.
369 RenderViewHostImpl* pending_render_view_host_; 396 RenderFrameHostImpl* pending_render_frame_host_;
370 397
371 // Tracks information about any current pending cross-process navigation. 398 // Tracks information about any current pending cross-process navigation.
372 scoped_ptr<PendingNavigationParams> pending_nav_params_; 399 scoped_ptr<PendingNavigationParams> pending_nav_params_;
373 400
374 // If either of these is non-NULL, the pending navigation is to a chrome: 401 // If either of these is non-NULL, the pending navigation is to a chrome:
375 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is 402 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is
376 // used for when they reference the same object. If either is non-NULL, the 403 // used for when they reference the same object. If either is non-NULL, the
377 // other should be NULL. 404 // other should be NULL.
378 scoped_ptr<WebUIImpl> pending_web_ui_; 405 scoped_ptr<WebUIImpl> pending_web_ui_;
379 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; 406 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_;
380 407
381 // A map of site instance ID to swapped out RenderViewHosts. This may include 408 // A map of site instance ID to swapped out RenderFrameHosts. This may
382 // pending_render_view_host_ for navigations to existing entries. 409 // include pending_render_frame_host_ for navigations to existing entries.
383 typedef base::hash_map<int32, RenderViewHostImpl*> RenderViewHostMap; 410 typedef base::hash_map<int32, RenderFrameHostImpl*> RenderFrameHostMap;
384 RenderViewHostMap swapped_out_hosts_; 411 RenderFrameHostMap swapped_out_hosts_;
385 412
386 // The intersitial page currently shown if any, not own by this class 413 // The intersitial page currently shown if any, not own by this class
387 // (the InterstitialPage is self-owned, it deletes itself when hidden). 414 // (the InterstitialPage is self-owned, it deletes itself when hidden).
388 InterstitialPageImpl* interstitial_page_; 415 InterstitialPageImpl* interstitial_page_;
389 416
390 NotificationRegistrar registrar_; 417 NotificationRegistrar registrar_;
391 418
392 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager); 419 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager);
393 }; 420 };
394 421
395 } // namespace content 422 } // namespace content
396 423
397 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_VIEW_HOST_MANAGER_H_ 424 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_VIEW_HOST_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698