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/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 InterstitialPageImpl; | 22 class InterstitialPageImpl; |
23 class NavigationControllerImpl; | 23 class NavigationControllerImpl; |
24 class NavigationEntry; | 24 class NavigationEntry; |
25 class NavigationEntryImpl; | 25 class NavigationEntryImpl; |
26 class RenderFrameHostDelegate; | 26 class RenderFrameHostDelegate; |
27 class RenderFrameHostImpl; | |
27 class RenderFrameHostManagerTest; | 28 class RenderFrameHostManagerTest; |
28 class RenderViewHost; | 29 class RenderViewHost; |
29 class RenderViewHostImpl; | 30 class RenderViewHostImpl; |
30 class RenderWidgetHostDelegate; | 31 class RenderWidgetHostDelegate; |
31 class RenderWidgetHostView; | 32 class RenderWidgetHostView; |
32 class TestWebContents; | 33 class TestWebContents; |
33 class WebUIImpl; | 34 class WebUIImpl; |
34 | 35 |
35 // Manages RenderFrameHosts for a FrameTreeNode. This class acts as a state | 36 // Manages RenderFrameHosts for a FrameTreeNode. This class acts as a state |
36 // machine to make cross-process navigations in a frame possible. | 37 // machine to make cross-process navigations in a frame possible. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 RenderWidgetHostDelegate* render_widget_delegate, | 120 RenderWidgetHostDelegate* render_widget_delegate, |
120 Delegate* delegate); | 121 Delegate* delegate); |
121 virtual ~RenderFrameHostManager(); | 122 virtual ~RenderFrameHostManager(); |
122 | 123 |
123 // For arguments, see WebContentsImpl constructor. | 124 // For arguments, see WebContentsImpl constructor. |
124 void Init(BrowserContext* browser_context, | 125 void Init(BrowserContext* browser_context, |
125 SiteInstance* site_instance, | 126 SiteInstance* site_instance, |
126 int routing_id, | 127 int routing_id, |
127 int main_frame_routing_id); | 128 int main_frame_routing_id); |
128 | 129 |
129 // Returns the currently active RenderViewHost. | 130 // Returns the currently active RenderFrameHost. |
130 // | 131 // |
131 // This will be non-NULL between Init() and Shutdown(). You may want to NULL | 132 // This will be non-NULL between Init() and Shutdown(). You may want to NULL |
132 // check it in many cases, however. Windows can send us messages during the | 133 // check it in many cases, however. Windows can send us messages during the |
133 // destruction process after it has been shut down. | 134 // destruction process after it has been shut down. |
135 RenderFrameHostImpl* current_frame() const { | |
136 return render_frame_host_; | |
137 } | |
138 | |
139 // TODO(creis): Remove this when we no longer use RVH for navigation. | |
134 RenderViewHostImpl* current_host() const; | 140 RenderViewHostImpl* current_host() const; |
135 | 141 |
136 // Returns the view associated with the current RenderViewHost, or NULL if | 142 // Returns the view associated with the current RenderViewHost, or NULL if |
137 // there is no current one. | 143 // there is no current one. |
138 RenderWidgetHostView* GetRenderWidgetHostView() const; | 144 RenderWidgetHostView* GetRenderWidgetHostView() const; |
139 | 145 |
140 // 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. |
nasko
2013/12/12 02:22:12
"render frame host"
Charlie Reis
2013/12/12 18:19:30
Oops, done.
| |
147 RenderFrameHostImpl* pending_render_frame_host() const; | |
nasko
2013/12/12 02:22:12
This seems a bit inconsistent: current_frame() vs
Charlie Reis
2013/12/12 18:19:30
current_frame_host() and pending_frame_host() soun
| |
148 | |
149 // TODO(creis): Remove this when we no longer use RVH for navigation. | |
141 RenderViewHostImpl* pending_render_view_host() const; | 150 RenderViewHostImpl* pending_render_view_host() const; |
142 | 151 |
143 // Returns the current committed Web UI or NULL if none applies. | 152 // Returns the current committed Web UI or NULL if none applies. |
144 WebUIImpl* web_ui() const { return web_ui_.get(); } | 153 WebUIImpl* web_ui() const { return web_ui_.get(); } |
145 | 154 |
146 // Returns the Web UI for the pending navigation, or NULL of none applies. | 155 // Returns the Web UI for the pending navigation, or NULL of none applies. |
147 WebUIImpl* pending_web_ui() const { | 156 WebUIImpl* pending_web_ui() const { |
148 return pending_web_ui_.get() ? pending_web_ui_.get() : | 157 return pending_web_ui_.get() ? pending_web_ui_.get() : |
149 pending_and_current_web_ui_.get(); | 158 pending_and_current_web_ui_.get(); |
150 } | 159 } |
(...skipping 25 matching lines...) Expand all Loading... | |
176 // The RenderViewHost has been swapped out, so we should resume the pending | 185 // The RenderViewHost has been swapped out, so we should resume the pending |
177 // network response and allow the pending RenderViewHost to commit. | 186 // network response and allow the pending RenderViewHost to commit. |
178 void SwappedOut(RenderViewHost* render_view_host); | 187 void SwappedOut(RenderViewHost* render_view_host); |
179 | 188 |
180 // Called when a renderer's main frame navigates. | 189 // Called when a renderer's main frame navigates. |
181 void DidNavigateMainFrame(RenderViewHost* render_view_host); | 190 void DidNavigateMainFrame(RenderViewHost* render_view_host); |
182 | 191 |
183 // Called when a renderer sets its opener to null. | 192 // Called when a renderer sets its opener to null. |
184 void DidDisownOpener(RenderViewHost* render_view_host); | 193 void DidDisownOpener(RenderViewHost* render_view_host); |
185 | 194 |
186 // Helper method to create a RenderViewHost. If |swapped_out| is true, it | 195 // Helper method to create a RenderFrameHost. If |swapped_out| is true, it |
187 // will be initially placed on the swapped out hosts list. Otherwise, it | 196 // will be initially placed on the swapped out hosts list. Otherwise, it |
188 // will be used for a pending cross-site navigation. | 197 // will be used for a pending cross-site navigation. |
189 int CreateRenderView(SiteInstance* instance, | 198 int CreateRenderFrame(SiteInstance* instance, |
190 int opener_route_id, | 199 int opener_route_id, |
191 bool swapped_out, | 200 bool swapped_out, |
192 bool hidden); | 201 bool hidden); |
193 | 202 |
194 // Called when a provisional load on the given renderer is aborted. | 203 // Called when a provisional load on the given renderer is aborted. |
195 void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host); | 204 void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host); |
196 | 205 |
197 // Sets the passed passed interstitial as the currently showing interstitial. | 206 // Sets the passed passed interstitial as the currently showing interstitial. |
198 // |interstitial_page| should be non NULL (use the remove_interstitial_page | 207 // |interstitial_page| should be non NULL (use the remove_interstitial_page |
199 // method to unset the interstitial) and no interstitial page should be set | 208 // method to unset the interstitial) and no interstitial page should be set |
200 // when there is already a non NULL interstitial page set. | 209 // when there is already a non NULL interstitial page set. |
201 void set_interstitial_page(InterstitialPageImpl* interstitial_page) { | 210 void set_interstitial_page(InterstitialPageImpl* interstitial_page) { |
202 DCHECK(!interstitial_page_ && interstitial_page); | 211 DCHECK(!interstitial_page_ && interstitial_page); |
(...skipping 26 matching lines...) Expand all Loading... | |
229 bool should_replace_current_entry) OVERRIDE; | 238 bool should_replace_current_entry) OVERRIDE; |
230 | 239 |
231 // NotificationObserver implementation. | 240 // NotificationObserver implementation. |
232 virtual void Observe(int type, | 241 virtual void Observe(int type, |
233 const NotificationSource& source, | 242 const NotificationSource& source, |
234 const NotificationDetails& details) OVERRIDE; | 243 const NotificationDetails& details) OVERRIDE; |
235 | 244 |
236 // Called when a RenderViewHost is about to be deleted. | 245 // Called when a RenderViewHost is about to be deleted. |
237 void RenderViewDeleted(RenderViewHost* rvh); | 246 void RenderViewDeleted(RenderViewHost* rvh); |
238 | 247 |
239 // Returns whether the given RenderViewHost is on the list of swapped out | 248 // Returns whether the given RenderFrameHost (or its associated |
240 // RenderViewHosts. | 249 // RenderViewHost) is on the list of swapped out RenderFrameHosts. |
241 bool IsOnSwappedOutList(RenderViewHost* rvh) const; | 250 bool IsRVHOnSwappedOutList(RenderViewHostImpl* rvh) const; |
251 bool IsOnSwappedOutList(RenderFrameHostImpl* rfh) const; | |
242 | 252 |
243 // Returns the swapped out RenderViewHost for the given SiteInstance, if any. | 253 // Returns the swapped out RenderViewHost or RenderFrameHost for the given |
244 RenderViewHostImpl* GetSwappedOutRenderViewHost(SiteInstance* instance); | 254 // SiteInstance, if any. |
255 RenderViewHostImpl* GetSwappedOutRenderViewHost(SiteInstance* instance) const; | |
256 RenderFrameHostImpl* GetSwappedOutRenderFrameHost( | |
257 SiteInstance* instance) const; | |
245 | 258 |
246 // Runs the unload handler in the current page, when we know that a pending | 259 // Runs the unload handler in the current page, when we know that a pending |
247 // cross-process navigation is going to commit. We may initiate a transfer | 260 // cross-process navigation is going to commit. We may initiate a transfer |
248 // to a new process after this completes or times out. | 261 // to a new process after this completes or times out. |
249 void SwapOutOldPage(); | 262 void SwapOutOldPage(); |
250 | 263 |
251 private: | 264 private: |
252 friend class RenderFrameHostManagerTest; | 265 friend class RenderFrameHostManagerTest; |
253 friend class TestWebContents; | 266 friend class TestWebContents; |
254 | 267 |
255 // Tracks information about a navigation while a cross-process transition is | 268 // Tracks information about a navigation while a cross-process transition is |
256 // in progress, in case we need to transfer it to a new RenderViewHost. | 269 // in progress, in case we need to transfer it to a new RenderFrameHost. |
257 struct PendingNavigationParams { | 270 struct PendingNavigationParams { |
258 PendingNavigationParams(); | 271 PendingNavigationParams(); |
259 PendingNavigationParams(const GlobalRequestID& global_request_id, | 272 PendingNavigationParams(const GlobalRequestID& global_request_id, |
260 bool is_transfer, | 273 bool is_transfer, |
261 const std::vector<GURL>& transfer_url, | 274 const std::vector<GURL>& transfer_url, |
262 Referrer referrer, | 275 Referrer referrer, |
263 PageTransition page_transition, | 276 PageTransition page_transition, |
264 int64 frame_id, | 277 int64 frame_id, |
265 bool should_replace_current_entry); | 278 bool should_replace_current_entry); |
266 ~PendingNavigationParams(); | 279 ~PendingNavigationParams(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 | 331 |
319 // Returns an appropriate SiteInstance object for the given NavigationEntry, | 332 // Returns an appropriate SiteInstance object for the given NavigationEntry, |
320 // possibly reusing the current SiteInstance. If --process-per-tab is used, | 333 // possibly reusing the current SiteInstance. If --process-per-tab is used, |
321 // this is only called when ShouldSwapBrowsingInstancesForNavigation returns | 334 // this is only called when ShouldSwapBrowsingInstancesForNavigation returns |
322 // true. | 335 // true. |
323 SiteInstance* GetSiteInstanceForEntry( | 336 SiteInstance* GetSiteInstanceForEntry( |
324 const NavigationEntryImpl& entry, | 337 const NavigationEntryImpl& entry, |
325 SiteInstance* current_instance, | 338 SiteInstance* current_instance, |
326 bool force_browsing_instance_swap); | 339 bool force_browsing_instance_swap); |
327 | 340 |
328 // Sets up the necessary state for a new RenderViewHost with the given opener. | 341 // Sets up the necessary state for a new RenderFrameHost with the given |
342 // opener. This also initializes the RenderView if necessary. | |
nasko
2013/12/12 02:22:12
nit: "RenderViewHost" here and next line.
Charlie Reis
2013/12/12 18:19:30
Done.
I looked closer and we're not really doing
| |
343 // TODO(creis): opener_route_id is currently for the RenderView but should be | |
344 // for the RenderFrame, since frames can have openers. | |
329 bool InitRenderView(RenderViewHost* render_view_host, int opener_route_id); | 345 bool InitRenderView(RenderViewHost* render_view_host, int opener_route_id); |
330 | 346 |
331 // Sets the pending RenderViewHost/WebUI to be the active one. Note that this | 347 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this |
332 // doesn't require the pending render_view_host_ pointer to be non-NULL, since | 348 // doesn't require the pending render_frame_host_ pointer to be non-NULL, |
333 // there could be Web UI switching as well. Call this for every commit. | 349 // since there could be Web UI switching as well. Call this for every commit. |
334 void CommitPending(); | 350 void CommitPending(); |
335 | 351 |
336 // Shutdown all RenderViewHosts in a SiteInstance. This is called | 352 // Shutdown all RenderFrameHosts in a SiteInstance. This is called to shutdown |
337 // to shutdown views when all the views in a SiteInstance are | 353 // frames when all the frames in a SiteInstance are confirmed to be swapped |
338 // confirmed to be swapped out. | 354 // out. |
339 void ShutdownRenderViewHostsInSiteInstance(int32 site_instance_id); | 355 void ShutdownRenderFrameHostsInSiteInstance(int32 site_instance_id); |
340 | 356 |
341 // Helper method to terminate the pending RenderViewHost. | 357 // Helper method to terminate the pending RenderViewHost. |
342 void CancelPending(); | 358 void CancelPending(); |
343 | 359 |
344 RenderViewHostImpl* UpdateRendererStateForNavigate( | 360 RenderFrameHostImpl* UpdateRendererStateForNavigate( |
345 const NavigationEntryImpl& entry); | 361 const NavigationEntryImpl& entry); |
346 | 362 |
347 // Called when a renderer process is starting to close. We should not | 363 // Called when a renderer process is starting to close. We should not |
348 // schedule new navigations in its swapped out RenderViewHosts after this. | 364 // schedule new navigations in its swapped out RenderFrameHosts after this. |
349 void RendererProcessClosing(RenderProcessHost* render_process_host); | 365 void RendererProcessClosing(RenderProcessHost* render_process_host); |
350 | 366 |
351 // Our delegate, not owned by us. Guaranteed non-NULL. | 367 // Our delegate, not owned by us. Guaranteed non-NULL. |
352 Delegate* delegate_; | 368 Delegate* delegate_; |
353 | 369 |
354 // Whether a navigation requiring different RenderView's is pending. This is | 370 // Whether a navigation requiring different RenderFrameHosts is pending. This |
355 // either cross-site request is (in the new process model), or when required | 371 // is either for cross-site requests or when required for the process type |
356 // for the view type (like view source versus not). | 372 // (like WebUI). |
357 bool cross_navigation_pending_; | 373 bool cross_navigation_pending_; |
358 | 374 |
359 // Implemented by the owner of this class, these delegates are installed into | 375 // Implemented by the owner of this class. These delegates are installed into |
360 // all the RenderViewHosts that we create. | 376 // all the RenderFrameHosts that we create. |
361 RenderFrameHostDelegate* render_frame_delegate_; | 377 RenderFrameHostDelegate* render_frame_delegate_; |
362 RenderViewHostDelegate* render_view_delegate_; | 378 RenderViewHostDelegate* render_view_delegate_; |
363 RenderWidgetHostDelegate* render_widget_delegate_; | 379 RenderWidgetHostDelegate* render_widget_delegate_; |
364 | 380 |
365 // Our RenderView host and its associated Web UI (if any, will be NULL for | 381 // Our RenderFrameHost and its associated Web UI (if any, will be NULL for |
366 // non-DOM-UI pages). This object is responsible for all communication with | 382 // non-WebUI pages). This object is responsible for all communication with |
367 // a child RenderView instance. | 383 // a child RenderFrame instance. |
368 RenderViewHostImpl* render_view_host_; | 384 // For now, RenderFrameHost keeps a RenderViewHost in its SiteInstance alive. |
385 // Eventually, RenderViewHost will be replaced with a page context. | |
386 RenderFrameHostImpl* render_frame_host_; | |
369 scoped_ptr<WebUIImpl> web_ui_; | 387 scoped_ptr<WebUIImpl> web_ui_; |
370 | 388 |
371 // A RenderViewHost used to load a cross-site page. This remains hidden | 389 // A RenderFrameHost used to load a cross-site page. This remains hidden |
372 // while a cross-site request is pending until it calls DidNavigate. It may | 390 // while a cross-site request is pending until it calls DidNavigate. It may |
373 // have an associated Web UI, in which case the Web UI pointer will be non- | 391 // have an associated Web UI, in which case the Web UI pointer will be non- |
374 // NULL. | 392 // NULL. |
375 // | 393 // |
376 // The |pending_web_ui_| may be non-NULL even when the | 394 // The |pending_web_ui_| may be non-NULL even when the |
377 // |pending_render_view_host_| is NULL. This will happen when we're | 395 // |pending_render_frame_host_| is NULL. This will happen when we're |
378 // transitioning between two Web UI pages: the RVH won't be swapped, so the | 396 // transitioning between two Web UI pages: the RFH won't be swapped, so the |
379 // pending pointer will be unused, but there will be a pending Web UI | 397 // pending pointer will be unused, but there will be a pending Web UI |
380 // associated with the navigation. | 398 // associated with the navigation. |
381 RenderViewHostImpl* pending_render_view_host_; | 399 RenderFrameHostImpl* pending_render_frame_host_; |
382 | 400 |
383 // Tracks information about any current pending cross-process navigation. | 401 // Tracks information about any current pending cross-process navigation. |
384 scoped_ptr<PendingNavigationParams> pending_nav_params_; | 402 scoped_ptr<PendingNavigationParams> pending_nav_params_; |
385 | 403 |
386 // If either of these is non-NULL, the pending navigation is to a chrome: | 404 // If either of these is non-NULL, the pending navigation is to a chrome: |
387 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is | 405 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is |
388 // used for when they reference the same object. If either is non-NULL, the | 406 // used for when they reference the same object. If either is non-NULL, the |
389 // other should be NULL. | 407 // other should be NULL. |
390 scoped_ptr<WebUIImpl> pending_web_ui_; | 408 scoped_ptr<WebUIImpl> pending_web_ui_; |
391 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; | 409 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; |
392 | 410 |
393 // A map of site instance ID to swapped out RenderViewHosts. This may include | 411 // A map of site instance ID to swapped out RenderFrameHosts. This may |
394 // pending_render_view_host_ for navigations to existing entries. | 412 // include pending_render_frame_host_ for navigations to existing entries. |
395 typedef base::hash_map<int32, RenderViewHostImpl*> RenderViewHostMap; | 413 typedef base::hash_map<int32, RenderFrameHostImpl*> RenderFrameHostMap; |
396 RenderViewHostMap swapped_out_hosts_; | 414 RenderFrameHostMap swapped_out_hosts_; |
397 | 415 |
398 // The intersitial page currently shown if any, not own by this class | 416 // The intersitial page currently shown if any, not own by this class |
399 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 417 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
400 InterstitialPageImpl* interstitial_page_; | 418 InterstitialPageImpl* interstitial_page_; |
401 | 419 |
402 NotificationRegistrar registrar_; | 420 NotificationRegistrar registrar_; |
403 | 421 |
404 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); | 422 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); |
405 }; | 423 }; |
406 | 424 |
407 } // namespace content | 425 } // namespace content |
408 | 426 |
409 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ | 427 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ |
OLD | NEW |